diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 8d1fc08f2ee8cb..735982a9b72a42 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -101,6 +101,14 @@ - (id)strongObject return aNumber; } +/* BEGIN DRAGONS: Note methods here cannot be renamed, and are used by private callers, do not rename, remove or modify behavior here */ + +@interface NSObject (MatterPrivateForInternalDragonsDoNotFeed) +- (void)_deviceInternalStateChanged:(MTRDevice *)device; +@end + +/* END DRAGONS */ + #pragma mark - SubscriptionCallback class declaration using namespace chip; using namespace chip::app; @@ -949,6 +957,15 @@ - (void)_changeInternalState:(MTRInternalDeviceState)state _internalDeviceState = state; if (lastState != state) { MTR_LOG("%@ internal state change %lu => %lu", self, static_cast(lastState), static_cast(state)); + + /* BEGIN DRAGONS: This is a huge hack for a specific use case, do not rename, remove or modify behavior here */ + id delegate = _weakDelegate.strongObject; + if ([delegate respondsToSelector:@selector(_deviceInternalStateChanged:)]) { + dispatch_async(_delegateQueue, ^{ + [(id) delegate _deviceInternalStateChanged:self]; + }); + } + /* END DRAGONS */ } } @@ -3506,6 +3523,31 @@ - (void)removeClientDataForKey:(NSString *)key endpointID:(NSNumber *)endpointID @end +/* BEGIN DRAGONS: Note methods here cannot be renamed, and are used by private callers, do not rename, remove or modify behavior here */ + +@implementation MTRDevice (MatterPrivateForInternalDragonsDoNotFeed) + +- (BOOL)_deviceHasActiveSubscription +{ + std::lock_guard lock(_lock); + + return HaveSubscriptionEstablishedRightNow(_internalDeviceState); +} + +- (void)_deviceMayBeReachable +{ + assertChipStackLockedByCurrentThread(); + + MTR_LOG("%@ _deviceMayBeReachable called", self); + + [self _triggerResubscribeWithReason:"SPI client indicated the device may now be reachable" + nodeLikelyReachable:YES]; +} + +/* END DRAGONS */ + +@end + @implementation MTRDevice (Deprecated) + (MTRDevice *)deviceWithNodeID:(uint64_t)nodeID deviceController:(MTRDeviceController *)deviceController