|
28 | 28 | #import "MTRCommandTimedCheck.h"
|
29 | 29 | #import "MTRConversion.h"
|
30 | 30 | #import "MTRDefines_Internal.h"
|
| 31 | +#import "MTRDeviceControllerOverXPC.h" |
31 | 32 | #import "MTRDeviceController_Internal.h"
|
32 | 33 | #import "MTRDevice_Internal.h"
|
33 | 34 | #import "MTRError_Internal.h"
|
@@ -713,14 +714,34 @@ - (void)_triggerResubscribeWithReason:(const char *)reason nodeLikelyReachable:(
|
713 | 714 | }
|
714 | 715 | }
|
715 | 716 |
|
716 |
| -// Return YES if there's a valid delegate. As long as we have that, we are |
717 |
| -// responsible for dealing with the subscription bits, and doing read-throughs |
718 |
| -// when we can't establish a subscription won't help things either. |
| 717 | +// Return YES if we are in a state where, apart from communication issues with |
| 718 | +// the device, we will be able to get reports via our subscription. |
719 | 719 | - (BOOL)_subscriptionAbleToReport
|
720 | 720 | {
|
721 | 721 | std::lock_guard lock(_lock);
|
722 | 722 | id<MTRDeviceDelegate> delegate = _weakDelegate.strongObject;
|
723 |
| - return (delegate != nil); |
| 723 | + if (delegate == nil) { |
| 724 | + // No delegate definitely means no subscription. |
| 725 | + return NO; |
| 726 | + } |
| 727 | + |
| 728 | + // For unit testing only, matching logic in setDelegate |
| 729 | +#ifdef DEBUG |
| 730 | + id testDelegate = delegate; |
| 731 | + if ([testDelegate respondsToSelector:@selector(unitTestShouldSetUpSubscriptionForDevice:)]) { |
| 732 | + if (![testDelegate unitTestShouldSetUpSubscriptionForDevice:self]) { |
| 733 | + return NO; |
| 734 | + } |
| 735 | + } |
| 736 | +#endif |
| 737 | + |
| 738 | + // Unfortunately, we currently have no subscriptions over our hacked-up XPC |
| 739 | + // setup. Try to detect that situation. |
| 740 | + if ([_deviceController.class respondsToSelector:@selector(sharedControllerWithID:xpcConnectBlock:)]) { |
| 741 | + return NO; |
| 742 | + } |
| 743 | + |
| 744 | + return YES; |
724 | 745 | }
|
725 | 746 |
|
726 | 747 | // Notification that read-through was skipped for an attribute read.
|
|
0 commit comments