From 5bc5e68978b2923ebc4fad7bf733145fdf4e46d9 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Fri, 1 Jul 2022 13:03:22 -0700 Subject: [PATCH] Restyling --- .../commands/clusters/ModelCommandBridge.mm | 36 +- .../commands/pairing/PairingCommandBridge.mm | 85 +- .../Framework/CHIP/MTRCluster_internal.h | 3 +- .../Framework/CHIP/MTRDeviceController.mm | 6 +- .../CHIP/MTRDeviceControllerOverXPC.m | 4 +- .../CHIP/zap-generated/MTRClustersObjc.mm | 4 +- .../Framework/CHIPTests/MTRClustersTests.m | 22 +- .../Framework/CHIPTests/MTRControllerTests.m | 8 +- .../Framework/CHIPTests/MTRDeviceTests.m | 20 +- .../CHIPTests/MTRXPCListenerSampleTests.m | 283 ++-- .../Framework/CHIPTests/MTRXPCProtocolTests.m | 1198 ++++++++--------- 11 files changed, 830 insertions(+), 839 deletions(-) diff --git a/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.mm b/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.mm index 367142dcabfcf3..e039391b8e6289 100644 --- a/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.mm +++ b/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.mm @@ -32,24 +32,24 @@ [commissioner getDevice:mNodeId queue:callbackQueue completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - if (error != nil) { - SetCommandExitStatus(error, "Error getting connected device"); - return; - } - - CHIP_ERROR err; - if (device == nil) { - err = CHIP_ERROR_INTERNAL; - } else { - err = SendCommand(device, mEndPointId); - } - - if (err != CHIP_NO_ERROR) { - ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err)); - SetCommandExitStatus(err); - return; - } - }]; + if (error != nil) { + SetCommandExitStatus(error, "Error getting connected device"); + return; + } + + CHIP_ERROR err; + if (device == nil) { + err = CHIP_ERROR_INTERNAL; + } else { + err = SendCommand(device, mEndPointId); + } + + if (err != CHIP_NO_ERROR) { + ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err)); + SetCommandExitStatus(err); + return; + } + }]; return CHIP_NO_ERROR; } diff --git a/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.mm b/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.mm index ca2115819d0c63..8a6935e9c6df34 100644 --- a/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.mm +++ b/examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.mm @@ -111,47 +111,46 @@ { dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip-tool.command", DISPATCH_QUEUE_SERIAL); MTRDeviceController * commissioner = CurrentCommissioner(); - [commissioner - getDevice:mNodeId - queue:callbackQueue -completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - CHIP_ERROR err = CHIP_NO_ERROR; - if (error) { - err = MTRErrorToCHIPErrorCode(error); - LogNSError("Error: ", error); - SetCommandExitStatus(err); - } else if (device == nil) { - ChipLogError(chipTool, "Error: %s", chip::ErrorStr(CHIP_ERROR_INTERNAL)); - SetCommandExitStatus(CHIP_ERROR_INTERNAL); - } else { - ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId); - MTROperationalCredentials * opCredsCluster = [[MTROperationalCredentials alloc] initWithDevice:device - endpoint:0 - queue:callbackQueue]; - [opCredsCluster readAttributeCurrentFabricIndexWithCompletionHandler:^( - NSNumber * _Nullable value, NSError * _Nullable readError) { - if (readError) { - CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError); - LogNSError("Failed to get current fabric: ", readError); - SetCommandExitStatus(readErr); - return; - } - MTROperationalCredentialsClusterRemoveFabricParams * params = - [[MTROperationalCredentialsClusterRemoveFabricParams alloc] init]; - params.fabricIndex = value; - [opCredsCluster removeFabricWithParams:params - completionHandler:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data, - NSError * _Nullable removeError) { - CHIP_ERROR removeErr = CHIP_NO_ERROR; - if (removeError) { - removeErr = MTRErrorToCHIPErrorCode(removeError); - LogNSError("Failed to remove current fabric: ", removeError); - } else { - ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId); - } - SetCommandExitStatus(removeErr); - }]; - }]; - } - }]; + [commissioner getDevice:mNodeId + queue:callbackQueue + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + CHIP_ERROR err = CHIP_NO_ERROR; + if (error) { + err = MTRErrorToCHIPErrorCode(error); + LogNSError("Error: ", error); + SetCommandExitStatus(err); + } else if (device == nil) { + ChipLogError(chipTool, "Error: %s", chip::ErrorStr(CHIP_ERROR_INTERNAL)); + SetCommandExitStatus(CHIP_ERROR_INTERNAL); + } else { + ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId); + MTROperationalCredentials * opCredsCluster = [[MTROperationalCredentials alloc] initWithDevice:device + endpoint:0 + queue:callbackQueue]; + [opCredsCluster readAttributeCurrentFabricIndexWithCompletionHandler:^( + NSNumber * _Nullable value, NSError * _Nullable readError) { + if (readError) { + CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError); + LogNSError("Failed to get current fabric: ", readError); + SetCommandExitStatus(readErr); + return; + } + MTROperationalCredentialsClusterRemoveFabricParams * params = + [[MTROperationalCredentialsClusterRemoveFabricParams alloc] init]; + params.fabricIndex = value; + [opCredsCluster removeFabricWithParams:params + completionHandler:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data, + NSError * _Nullable removeError) { + CHIP_ERROR removeErr = CHIP_NO_ERROR; + if (removeError) { + removeErr = MTRErrorToCHIPErrorCode(removeError); + LogNSError("Failed to remove current fabric: ", removeError); + } else { + ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId); + } + SetCommandExitStatus(removeErr); + }]; + }]; + } + }]; } diff --git a/src/darwin/Framework/CHIP/MTRCluster_internal.h b/src/darwin/Framework/CHIP/MTRCluster_internal.h index ff172464c86647..7cb0bb86a7ed0e 100644 --- a/src/darwin/Framework/CHIP/MTRCluster_internal.h +++ b/src/darwin/Framework/CHIP/MTRCluster_internal.h @@ -21,12 +21,11 @@ #import "MTRDevice.h" #import "MTRDevice_Internal.h" -#import "zap-generated/MTRClustersObjc.h" #import "zap-generated/CHIPClusters.h" +#import "zap-generated/MTRClustersObjc.h" using namespace chip::app::Clusters; - @interface MTRCluster () @property (readonly, nonatomic) dispatch_queue_t callbackQueue; - (chip::Controller::ClusterBase *)getCluster; diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index 6e32db6b02f19b..90c56d5f3b9af5 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -39,9 +39,9 @@ #include -#include #include #include +#include #include #include #include @@ -519,9 +519,7 @@ - (MTRDevice *)getDeviceBeingCommissioned:(uint64_t)deviceId error:(NSError * __ return [[MTRDevice alloc] initWithDevice:deviceProxy]; } -- (BOOL)getDevice:(uint64_t)deviceID - queue:(dispatch_queue_t)queue -completionHandler:(MTRDeviceConnectionCallback)completionHandler +- (BOOL)getDevice:(uint64_t)deviceID queue:(dispatch_queue_t)queue completionHandler:(MTRDeviceConnectionCallback)completionHandler { __block CHIP_ERROR errorCode = CHIP_ERROR_INCORRECT_STATE; if (![self isRunning]) { diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.m b/src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.m index f3a4b57f4ba9a6..9bf71c2c7f62a6 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.m +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.m @@ -103,9 +103,7 @@ - (BOOL)deviceBeingCommissionedOverBLE:(uint64_t)deviceId return NO; } -- (BOOL)getDevice:(uint64_t)deviceID - queue:(dispatch_queue_t)queue -completionHandler:(MTRDeviceConnectionCallback)completionHandler +- (BOOL)getDevice:(uint64_t)deviceID queue:(dispatch_queue_t)queue completionHandler:(MTRDeviceConnectionCallback)completionHandler { dispatch_async(_workQueue, ^{ dispatch_group_t group = dispatch_group_create(); diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRClustersObjc.mm b/src/darwin/Framework/CHIP/zap-generated/MTRClustersObjc.mm index 94746c04cb4648..258c96cbbb4823 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRClustersObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRClustersObjc.mm @@ -60108,8 +60108,8 @@ - (void)launchContentWithParams:(MTRContentLauncherClusterLaunchContentParams *) } listFreer.add(listHolder_4); for (size_t i_4 = 0; i_4 < element_1.externalIDList.count; ++i_4) { - if (![element_1.externalIDList[i_4] - isKindOfClass:[MTRContentLauncherClusterAdditionalInfo class]]) { + if (! + [element_1.externalIDList[i_4] isKindOfClass:[MTRContentLauncherClusterAdditionalInfo class]]) { // Wrong kind of value. return; } diff --git a/src/darwin/Framework/CHIPTests/MTRClustersTests.m b/src/darwin/Framework/CHIPTests/MTRClustersTests.m index d855633959daa0..f6aebf6b0e5bb0 100644 --- a/src/darwin/Framework/CHIPTests/MTRClustersTests.m +++ b/src/darwin/Framework/CHIPTests/MTRClustersTests.m @@ -142,10 +142,10 @@ - (void)testInitStack [controller getDevice:nodeId queue:dispatch_get_main_queue() completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertEqual(error.code, 0); - [connectionExpectation fulfill]; - connectionExpectation = nil; - }]; + XCTAssertEqual(error.code, 0); + [connectionExpectation fulfill]; + connectionExpectation = nil; + }]; [self waitForExpectationsWithTimeout:kCASESetupTimeoutInSeconds handler:nil]; } @@ -169,13 +169,13 @@ - (void)testReuseChipClusterObject __block MTRDevice * device; __block XCTestExpectation * connectionExpectation = [self expectationWithDescription:@"CASE established"]; [controller getDevice:nodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable retrievedDevice, NSError * _Nullable error) { - XCTAssertEqual(error.code, 0); - [connectionExpectation fulfill]; - connectionExpectation = nil; - device = retrievedDevice; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable retrievedDevice, NSError * _Nullable error) { + XCTAssertEqual(error.code, 0); + [connectionExpectation fulfill]; + connectionExpectation = nil; + device = retrievedDevice; + }]; [self waitForExpectationsWithTimeout:kCASESetupTimeoutInSeconds handler:nil]; XCTestExpectation * expectation = [self expectationWithDescription:@"ReuseMTRClusterObjectFirstCall"]; diff --git a/src/darwin/Framework/CHIPTests/MTRControllerTests.m b/src/darwin/Framework/CHIPTests/MTRControllerTests.m index 6562004747dfe3..9d3b3e462e5a9a 100644 --- a/src/darwin/Framework/CHIPTests/MTRControllerTests.m +++ b/src/darwin/Framework/CHIPTests/MTRControllerTests.m @@ -182,10 +182,10 @@ - (void)testControllerInvalidAccess XCTAssertFalse([controller isRunning]); XCTAssertFalse([controller getDevice:1234 - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) { - XCTAssertEqual(error.code, MTRErrorCodeInvalidState); - }]); + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) { + XCTAssertEqual(error.code, MTRErrorCodeInvalidState); + }]); [factory shutdown]; XCTAssertFalse([factory isRunning]); diff --git a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m index b030092ee99308..8ff62215c30f72 100644 --- a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m +++ b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m @@ -63,10 +63,10 @@ static void WaitForCommissionee(XCTestExpectation * expectation, dispatch_queue_ [controller getDevice:kDeviceId queue:dispatch_get_main_queue() completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertEqual(error.code, 0); - [expectation fulfill]; - mConnectedDevice = device; - }]; + XCTAssertEqual(error.code, 0); + [expectation fulfill]; + mConnectedDevice = device; + }]; } static MTRDevice * GetConnectedDevice(void) @@ -178,12 +178,12 @@ - (void)initStack __block XCTestExpectation * connectionExpectation = [self expectationWithDescription:@"CASE established"]; [controller getDevice:kDeviceId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertEqual(error.code, 0); - [connectionExpectation fulfill]; - connectionExpectation = nil; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertEqual(error.code, 0); + [connectionExpectation fulfill]; + connectionExpectation = nil; + }]; [self waitForExpectationsWithTimeout:kCASESetupTimeoutInSeconds handler:nil]; } diff --git a/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m b/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m index 146fad48849ce7..a61d6a1e60e658 100644 --- a/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m +++ b/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m @@ -173,22 +173,21 @@ - (void)readAttributeWithController:(id)controller [sharedController getDevice:nodeId queue:dispatch_get_main_queue() completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - if (error) { - NSLog(@"Failed to get connected device"); - completion(nil, error); - } else { - [device - readAttributeWithEndpointId:endpointId - clusterId:clusterId - attributeId:attributeId - params:[MTRDeviceController decodeXPCReadParams:params] - clientQueue:dispatch_get_main_queue() - completion:^(NSArray *> * _Nullable values, - NSError * _Nullable error) { - completion([MTRDeviceController encodeXPCResponseValues:values], error); - }]; - } - }]; + if (error) { + NSLog(@"Failed to get connected device"); + completion(nil, error); + } else { + [device readAttributeWithEndpointId:endpointId + clusterId:clusterId + attributeId:attributeId + params:[MTRDeviceController decodeXPCReadParams:params] + clientQueue:dispatch_get_main_queue() + completion:^(NSArray *> * _Nullable values, + NSError * _Nullable error) { + completion([MTRDeviceController encodeXPCResponseValues:values], error); + }]; + } + }]; } else { NSLog(@"Failed to get shared controller"); completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]); @@ -207,26 +206,25 @@ - (void)writeAttributeWithController:(id)controller (void) controller; __auto_type sharedController = sController; if (sharedController) { - [sharedController - getDevice:nodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - if (error) { - NSLog(@"Failed to get connected device"); - completion(nil, error); - } else { - [device writeAttributeWithEndpointId:endpointId - clusterId:clusterId - attributeId:attributeId - value:value - timedWriteTimeout:timeoutMs - clientQueue:dispatch_get_main_queue() - completion:^(NSArray *> * _Nullable values, - NSError * _Nullable error) { - completion([MTRDeviceController encodeXPCResponseValues:values], error); - }]; - } - }]; + [sharedController getDevice:nodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + if (error) { + NSLog(@"Failed to get connected device"); + completion(nil, error); + } else { + [device writeAttributeWithEndpointId:endpointId + clusterId:clusterId + attributeId:attributeId + value:value + timedWriteTimeout:timeoutMs + clientQueue:dispatch_get_main_queue() + completion:^(NSArray *> * _Nullable values, + NSError * _Nullable error) { + completion([MTRDeviceController encodeXPCResponseValues:values], error); + }]; + } + }]; } else { NSLog(@"Failed to get shared controller"); completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]); @@ -246,25 +244,24 @@ - (void)invokeCommandWithController:(id)controller __auto_type sharedController = sController; if (sharedController) { [sharedController getDevice:nodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - if (error) { - NSLog(@"Failed to get connected device"); - completion(nil, error); - } else { - [device - invokeCommandWithEndpointId:endpointId - clusterId:clusterId - commandId:commandId - commandFields:fields - timedInvokeTimeout:nil - clientQueue:dispatch_get_main_queue() - completion:^(NSArray *> * _Nullable values, - NSError * _Nullable error) { - completion([MTRDeviceController encodeXPCResponseValues:values], error); - }]; - } - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + if (error) { + NSLog(@"Failed to get connected device"); + completion(nil, error); + } else { + [device invokeCommandWithEndpointId:endpointId + clusterId:clusterId + commandId:commandId + commandFields:fields + timedInvokeTimeout:nil + clientQueue:dispatch_get_main_queue() + completion:^(NSArray *> * _Nullable values, + NSError * _Nullable error) { + completion([MTRDeviceController encodeXPCResponseValues:values], error); + }]; + } + }]; } else { NSLog(@"Failed to get shared controller"); completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]); @@ -283,39 +280,39 @@ - (void)subscribeAttributeWithController:(id)controller { __auto_type sharedController = sController; if (sharedController) { - [sharedController - getDevice:nodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - if (error) { - NSLog(@"Failed to get connected device"); - establishedHandler(); - // Send an error report so that the client knows of the failure - [self.clientProxy handleReportWithController:controller - nodeId:nodeId - values:nil - error:[NSError errorWithDomain:MTRErrorDomain - code:MTRErrorCodeGeneralError - userInfo:nil]]; - } else { - [device subscribeAttributeWithEndpointId:endpointId - clusterId:clusterId - attributeId:attributeId - minInterval:minInterval - maxInterval:maxInterval - params:[MTRDeviceController decodeXPCSubscribeParams:params] - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, - NSError * _Nullable error) { - [self.clientProxy handleReportWithController:controller - nodeId:nodeId - values:[MTRDeviceController - encodeXPCResponseValues:values] - error:error]; - } - subscriptionEstablished:establishedHandler]; - } - }]; + [sharedController getDevice:nodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + if (error) { + NSLog(@"Failed to get connected device"); + establishedHandler(); + // Send an error report so that the client knows of the failure + [self.clientProxy handleReportWithController:controller + nodeId:nodeId + values:nil + error:[NSError errorWithDomain:MTRErrorDomain + code:MTRErrorCodeGeneralError + userInfo:nil]]; + } else { + [device subscribeAttributeWithEndpointId:endpointId + clusterId:clusterId + attributeId:attributeId + minInterval:minInterval + maxInterval:maxInterval + params:[MTRDeviceController decodeXPCSubscribeParams:params] + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, + NSError * _Nullable error) { + [self.clientProxy + handleReportWithController:controller + nodeId:nodeId + values:[MTRDeviceController + encodeXPCResponseValues:values] + error:error]; + } + subscriptionEstablished:establishedHandler]; + } + }]; } else { NSLog(@"Failed to get shared controller"); establishedHandler(); @@ -334,14 +331,14 @@ - (void)stopReportsWithController:(id _Nullable)controller nodeId:(uint64_t)node __auto_type sharedController = sController; if (sharedController) { [sharedController getDevice:nodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - if (error) { - NSLog(@"Failed to get connected device"); - } else { - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() completion:completion]; - } - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + if (error) { + NSLog(@"Failed to get connected device"); + } else { + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() completion:completion]; + } + }]; } else { NSLog(@"Failed to get shared controller"); completion(); @@ -364,42 +361,42 @@ - (void)subscribeWithController:(id _Nullable)controller } [sharedController getDevice:nodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - if (error) { - NSLog(@"Error: Failed to get connected device (%llu) for attribute cache: %@", nodeId, error); - completion(error); - return; - } - NSMutableArray * established = [NSMutableArray arrayWithCapacity:1]; - [established addObject:@NO]; - [device subscribeWithQueue:dispatch_get_main_queue() - minInterval:[minInterval unsignedShortValue] - maxInterval:[maxInterval unsignedShortValue] - params:[MTRDeviceController decodeXPCSubscribeParams:params] - cacheContainer:attributeCacheContainer - attributeReportHandler:^(NSArray * value) { - NSLog(@"Received report: %@", value); - } - eventReportHandler:nil - errorHandler:^(NSError * error) { - NSLog(@"Received report error: %@", error); - if (![established[0] boolValue]) { - established[0] = @YES; - completion(error); - } - } - subscriptionEstablished:^() { - NSLog(@"Attribute cache subscription succeeded for device %llu", nodeId); - if (attributeCacheContainer) { - [self.attributeCacheDictionary setObject:attributeCacheContainer forKey:@(nodeId)]; - } - if (![established[0] boolValue]) { - established[0] = @YES; - completion(nil); - } - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + if (error) { + NSLog(@"Error: Failed to get connected device (%llu) for attribute cache: %@", nodeId, error); + completion(error); + return; + } + NSMutableArray * established = [NSMutableArray arrayWithCapacity:1]; + [established addObject:@NO]; + [device subscribeWithQueue:dispatch_get_main_queue() + minInterval:[minInterval unsignedShortValue] + maxInterval:[maxInterval unsignedShortValue] + params:[MTRDeviceController decodeXPCSubscribeParams:params] + cacheContainer:attributeCacheContainer + attributeReportHandler:^(NSArray * value) { + NSLog(@"Received report: %@", value); + } + eventReportHandler:nil + errorHandler:^(NSError * error) { + NSLog(@"Received report error: %@", error); + if (![established[0] boolValue]) { + established[0] = @YES; + completion(error); + } + } + subscriptionEstablished:^() { + NSLog(@"Attribute cache subscription succeeded for device %llu", nodeId); + if (attributeCacheContainer) { + [self.attributeCacheDictionary setObject:attributeCacheContainer forKey:@(nodeId)]; + } + if (![established[0] boolValue]) { + established[0] = @YES; + completion(nil); + } + }]; + }]; } else { NSLog(@"Failed to get shared controller"); completion([NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]); @@ -550,12 +547,12 @@ - (void)initStack __block XCTestExpectation * connectionExpectation = [self expectationWithDescription:@"CASE established"]; [controller getDevice:kDeviceId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertEqual(error.code, 0); - [connectionExpectation fulfill]; - connectionExpectation = nil; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertEqual(error.code, 0); + [connectionExpectation fulfill]; + connectionExpectation = nil; + }]; [self waitForExpectationsWithTimeout:kCASESetupTimeoutInSeconds handler:nil]; mSampleListener = [[MTRXPCListenerSample alloc] init]; @@ -593,11 +590,11 @@ - (void)waitForCommissionee return nil; }]; [remoteController getDevice:kDeviceId - queue:queue - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - mConnectedDevice = device; - [expectation fulfill]; - }]; + queue:queue + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + mConnectedDevice = device; + [expectation fulfill]; + }]; [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; mDeviceController = remoteController; } diff --git a/src/darwin/Framework/CHIPTests/MTRXPCProtocolTests.m b/src/darwin/Framework/CHIPTests/MTRXPCProtocolTests.m index 5dbb97356d63d5..b01535c07ad3bf 100644 --- a/src/darwin/Framework/CHIPTests/MTRXPCProtocolTests.m +++ b/src/darwin/Framework/CHIPTests/MTRXPCProtocolTests.m @@ -101,37 +101,37 @@ - (void)subscribeWithDeviceController:(MTRDeviceController *)deviceController [deviceController getDevice:deviceId queue:workQueue completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - if (error) { - NSLog(@"Error: Failed to get connected device (%llu) for attribute cache: %@", deviceId, error); - completionHandler(error); - return; - } - __auto_type established = [NSMutableArray arrayWithCapacity:1]; - [established addObject:@NO]; - [device subscribeWithQueue:clientQueue - minInterval:1 - maxInterval:43200 - params:params - cacheContainer:self - attributeReportHandler:^(NSArray * value) { - NSLog(@"Report received for attribute cache: %@", value); - } - eventReportHandler:nil - errorHandler:^(NSError * error) { - NSLog(@"Report error received for attribute cache: %@", error); - if (![established[0] boolValue]) { - established[0] = @YES; - completionHandler(error); - } - } - subscriptionEstablished:^() { - NSLog(@"Attribute cache subscription succeeded for device %llu", deviceId); - if (![established[0] boolValue]) { - established[0] = @YES; - completionHandler(nil); - } - }]; - }]; + if (error) { + NSLog(@"Error: Failed to get connected device (%llu) for attribute cache: %@", deviceId, error); + completionHandler(error); + return; + } + __auto_type established = [NSMutableArray arrayWithCapacity:1]; + [established addObject:@NO]; + [device subscribeWithQueue:clientQueue + minInterval:1 + maxInterval:43200 + params:params + cacheContainer:self + attributeReportHandler:^(NSArray * value) { + NSLog(@"Report received for attribute cache: %@", value); + } + eventReportHandler:nil + errorHandler:^(NSError * error) { + NSLog(@"Report error received for attribute cache: %@", error); + if (![established[0] boolValue]) { + established[0] = @YES; + completionHandler(error); + } + } + subscriptionEstablished:^() { + NSLog(@"Attribute cache subscription succeeded for device %llu", deviceId); + if (![established[0] boolValue]) { + established[0] = @YES; + completionHandler(nil); + } + }]; + }]; } @end @@ -364,26 +364,26 @@ - (void)testReadAttributeSuccess }; [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Reading..."); - [device readAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - params:nil - clientQueue:dispatch_get_main_queue() - completion:^(id _Nullable value, NSError * _Nullable error) { - NSLog(@"Read value: %@", value); - XCTAssertNotNil(value); - XCTAssertNil(error); - XCTAssertTrue([myValues isEqualTo:value]); - [responseExpectation fulfill]; - self.xpcDisconnectExpectation = - [self expectationWithDescription:@"XPC Disconnected"]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Reading..."); + [device readAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + params:nil + clientQueue:dispatch_get_main_queue() + completion:^(id _Nullable value, NSError * _Nullable error) { + NSLog(@"Read value: %@", value); + XCTAssertNotNil(value); + XCTAssertNil(error); + XCTAssertTrue([myValues isEqualTo:value]); + [responseExpectation fulfill]; + self.xpcDisconnectExpectation = + [self expectationWithDescription:@"XPC Disconnected"]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, responseExpectation, nil] timeout:kTimeoutInSeconds]; @@ -426,26 +426,26 @@ - (void)testReadAttributeWithParamsSuccess }; [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Reading..."); - [device readAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - params:myParams - clientQueue:dispatch_get_main_queue() - completion:^(id _Nullable value, NSError * _Nullable error) { - NSLog(@"Read value: %@", value); - XCTAssertNotNil(value); - XCTAssertNil(error); - XCTAssertTrue([myValues isEqualTo:value]); - [responseExpectation fulfill]; - self.xpcDisconnectExpectation = - [self expectationWithDescription:@"XPC Disconnected"]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Reading..."); + [device readAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + params:myParams + clientQueue:dispatch_get_main_queue() + completion:^(id _Nullable value, NSError * _Nullable error) { + NSLog(@"Read value: %@", value); + XCTAssertNotNil(value); + XCTAssertNil(error); + XCTAssertTrue([myValues isEqualTo:value]); + [responseExpectation fulfill]; + self.xpcDisconnectExpectation = + [self expectationWithDescription:@"XPC Disconnected"]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, responseExpectation, nil] timeout:kTimeoutInSeconds]; @@ -479,25 +479,25 @@ - (void)testReadAttributeFailure }; [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Reading..."); - [device readAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - params:nil - clientQueue:dispatch_get_main_queue() - completion:^(id _Nullable value, NSError * _Nullable error) { - NSLog(@"Read value: %@", value); - XCTAssertNil(value); - XCTAssertNotNil(error); - [responseExpectation fulfill]; - self.xpcDisconnectExpectation = - [self expectationWithDescription:@"XPC Disconnected"]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Reading..."); + [device readAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + params:nil + clientQueue:dispatch_get_main_queue() + completion:^(id _Nullable value, NSError * _Nullable error) { + NSLog(@"Read value: %@", value); + XCTAssertNil(value); + XCTAssertNotNil(error); + [responseExpectation fulfill]; + self.xpcDisconnectExpectation = + [self expectationWithDescription:@"XPC Disconnected"]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, responseExpectation, nil] timeout:kTimeoutInSeconds]; @@ -538,27 +538,27 @@ - (void)testWriteAttributeSuccess }; [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Writing..."); - [device writeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - value:myValue - timedWriteTimeout:nil - clientQueue:dispatch_get_main_queue() - completion:^(id _Nullable value, NSError * _Nullable error) { - NSLog(@"Write response: %@", value); - XCTAssertNotNil(value); - XCTAssertNil(error); - XCTAssertTrue([myResults isEqualTo:value]); - [responseExpectation fulfill]; - self.xpcDisconnectExpectation = - [self expectationWithDescription:@"XPC Disconnected"]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Writing..."); + [device writeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + value:myValue + timedWriteTimeout:nil + clientQueue:dispatch_get_main_queue() + completion:^(id _Nullable value, NSError * _Nullable error) { + NSLog(@"Write response: %@", value); + XCTAssertNotNil(value); + XCTAssertNil(error); + XCTAssertTrue([myResults isEqualTo:value]); + [responseExpectation fulfill]; + self.xpcDisconnectExpectation = + [self expectationWithDescription:@"XPC Disconnected"]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, responseExpectation, nil] timeout:kTimeoutInSeconds]; @@ -601,27 +601,27 @@ - (void)testTimedWriteAttributeSuccess }; [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Writing..."); - [device writeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - value:myValue - timedWriteTimeout:myTimedWriteTimeout - clientQueue:dispatch_get_main_queue() - completion:^(id _Nullable value, NSError * _Nullable error) { - NSLog(@"Write response: %@", value); - XCTAssertNotNil(value); - XCTAssertNil(error); - XCTAssertTrue([myResults isEqualTo:value]); - [responseExpectation fulfill]; - self.xpcDisconnectExpectation = - [self expectationWithDescription:@"XPC Disconnected"]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Writing..."); + [device writeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + value:myValue + timedWriteTimeout:myTimedWriteTimeout + clientQueue:dispatch_get_main_queue() + completion:^(id _Nullable value, NSError * _Nullable error) { + NSLog(@"Write response: %@", value); + XCTAssertNotNil(value); + XCTAssertNil(error); + XCTAssertTrue([myResults isEqualTo:value]); + [responseExpectation fulfill]; + self.xpcDisconnectExpectation = + [self expectationWithDescription:@"XPC Disconnected"]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, responseExpectation, nil] timeout:kTimeoutInSeconds]; @@ -657,26 +657,26 @@ - (void)testWriteAttributeFailure }; [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Writing..."); - [device writeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - value:myValue - timedWriteTimeout:nil - clientQueue:dispatch_get_main_queue() - completion:^(id _Nullable value, NSError * _Nullable error) { - NSLog(@"Write response: %@", value); - XCTAssertNil(value); - XCTAssertNotNil(error); - [responseExpectation fulfill]; - self.xpcDisconnectExpectation = - [self expectationWithDescription:@"XPC Disconnected"]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Writing..."); + [device writeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + value:myValue + timedWriteTimeout:nil + clientQueue:dispatch_get_main_queue() + completion:^(id _Nullable value, NSError * _Nullable error) { + NSLog(@"Write response: %@", value); + XCTAssertNil(value); + XCTAssertNotNil(error); + [responseExpectation fulfill]; + self.xpcDisconnectExpectation = + [self expectationWithDescription:@"XPC Disconnected"]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, responseExpectation, nil] timeout:kTimeoutInSeconds]; @@ -717,27 +717,27 @@ - (void)testInvokeCommandSuccess }; [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Invoking command..."); - [device invokeCommandWithEndpointId:myEndpointId - clusterId:myClusterId - commandId:myCommandId - commandFields:myFields - timedInvokeTimeout:nil - clientQueue:dispatch_get_main_queue() - completion:^(id _Nullable value, NSError * _Nullable error) { - NSLog(@"Command response: %@", value); - XCTAssertNotNil(value); - XCTAssertNil(error); - XCTAssertTrue([myResults isEqualTo:value]); - [responseExpectation fulfill]; - self.xpcDisconnectExpectation = - [self expectationWithDescription:@"XPC Disconnected"]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Invoking command..."); + [device invokeCommandWithEndpointId:myEndpointId + clusterId:myClusterId + commandId:myCommandId + commandFields:myFields + timedInvokeTimeout:nil + clientQueue:dispatch_get_main_queue() + completion:^(id _Nullable value, NSError * _Nullable error) { + NSLog(@"Command response: %@", value); + XCTAssertNotNil(value); + XCTAssertNil(error); + XCTAssertTrue([myResults isEqualTo:value]); + [responseExpectation fulfill]; + self.xpcDisconnectExpectation = + [self expectationWithDescription:@"XPC Disconnected"]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, responseExpectation, nil] timeout:kTimeoutInSeconds]; @@ -780,27 +780,27 @@ - (void)testTimedInvokeCommandSuccess }; [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Invoking command..."); - [device invokeCommandWithEndpointId:myEndpointId - clusterId:myClusterId - commandId:myCommandId - commandFields:myFields - timedInvokeTimeout:myTimedInvokeTimeout - clientQueue:dispatch_get_main_queue() - completion:^(id _Nullable value, NSError * _Nullable error) { - NSLog(@"Command response: %@", value); - XCTAssertNotNil(value); - XCTAssertNil(error); - XCTAssertTrue([myResults isEqualTo:value]); - [responseExpectation fulfill]; - self.xpcDisconnectExpectation = - [self expectationWithDescription:@"XPC Disconnected"]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Invoking command..."); + [device invokeCommandWithEndpointId:myEndpointId + clusterId:myClusterId + commandId:myCommandId + commandFields:myFields + timedInvokeTimeout:myTimedInvokeTimeout + clientQueue:dispatch_get_main_queue() + completion:^(id _Nullable value, NSError * _Nullable error) { + NSLog(@"Command response: %@", value); + XCTAssertNotNil(value); + XCTAssertNil(error); + XCTAssertTrue([myResults isEqualTo:value]); + [responseExpectation fulfill]; + self.xpcDisconnectExpectation = + [self expectationWithDescription:@"XPC Disconnected"]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, responseExpectation, nil] timeout:kTimeoutInSeconds]; @@ -839,26 +839,26 @@ - (void)testInvokeCommandFailure }; [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Invoking command..."); - [device invokeCommandWithEndpointId:myEndpointId - clusterId:myClusterId - commandId:myCommandId - commandFields:myFields - timedInvokeTimeout:nil - clientQueue:dispatch_get_main_queue() - completion:^(id _Nullable value, NSError * _Nullable error) { - NSLog(@"Command response: %@", value); - XCTAssertNil(value); - XCTAssertNotNil(error); - [responseExpectation fulfill]; - self.xpcDisconnectExpectation = - [self expectationWithDescription:@"XPC Disconnected"]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Invoking command..."); + [device invokeCommandWithEndpointId:myEndpointId + clusterId:myClusterId + commandId:myCommandId + commandFields:myFields + timedInvokeTimeout:nil + clientQueue:dispatch_get_main_queue() + completion:^(id _Nullable value, NSError * _Nullable error) { + NSLog(@"Command response: %@", value); + XCTAssertNil(value); + XCTAssertNotNil(error); + [responseExpectation fulfill]; + self.xpcDisconnectExpectation = + [self expectationWithDescription:@"XPC Disconnected"]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, responseExpectation, nil] timeout:kTimeoutInSeconds]; @@ -904,30 +904,30 @@ - (void)testSubscribeAttributeSuccess _xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"]; [_remoteDeviceController - getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Subscribing..."); - [device subscribeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - minInterval:myMinInterval - maxInterval:myMaxInterval - params:nil - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { - NSLog(@"Report value: %@", values); - XCTAssertNotNil(values); - XCTAssertNil(error); - XCTAssertTrue([myReport isEqualTo:values]); - [reportExpectation fulfill]; - } - subscriptionEstablished:^{ - [establishExpectation fulfill]; - }]; - }]; + getDevice:myNodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Subscribing..."); + [device subscribeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + minInterval:myMinInterval + maxInterval:myMaxInterval + params:nil + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { + NSLog(@"Report value: %@", values); + XCTAssertNotNil(values); + XCTAssertNil(error); + XCTAssertTrue([myReport isEqualTo:values]); + [reportExpectation fulfill]; + } + subscriptionEstablished:^{ + [establishExpectation fulfill]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, establishExpectation, nil] timeout:kTimeoutInSeconds]; @@ -968,14 +968,14 @@ - (void)testSubscribeAttributeSuccess // Deregister report handler [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + }]; + }]; // Wait for disconnection [self waitForExpectations:@[ _xpcDisconnectExpectation, stopExpectation ] timeout:kTimeoutInSeconds]; @@ -1024,30 +1024,30 @@ - (void)testSubscribeAttributeWithParamsSuccess _xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"]; [_remoteDeviceController - getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Subscribing..."); - [device subscribeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - minInterval:myMinInterval - maxInterval:myMaxInterval - params:myParams - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { - NSLog(@"Report value: %@", values); - XCTAssertNotNil(values); - XCTAssertNil(error); - XCTAssertTrue([myReport isEqualTo:values]); - [reportExpectation fulfill]; - } - subscriptionEstablished:^{ - [establishExpectation fulfill]; - }]; - }]; + getDevice:myNodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Subscribing..."); + [device subscribeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + minInterval:myMinInterval + maxInterval:myMaxInterval + params:myParams + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { + NSLog(@"Report value: %@", values); + XCTAssertNotNil(values); + XCTAssertNil(error); + XCTAssertTrue([myReport isEqualTo:values]); + [reportExpectation fulfill]; + } + subscriptionEstablished:^{ + [establishExpectation fulfill]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, establishExpectation, nil] timeout:kTimeoutInSeconds]; @@ -1088,14 +1088,14 @@ - (void)testSubscribeAttributeWithParamsSuccess // Deregister report handler [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + }]; + }]; // Wait for disconnection [self waitForExpectations:@[ _xpcDisconnectExpectation, stopExpectation ] timeout:kTimeoutInSeconds]; @@ -1139,30 +1139,30 @@ - (void)testBadlyFormattedReport _xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"]; [_remoteDeviceController - getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Subscribing..."); - [device subscribeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - minInterval:myMinInterval - maxInterval:myMaxInterval - params:nil - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { - NSLog(@"Report value: %@", values); - XCTAssertNotNil(values); - XCTAssertNil(error); - XCTAssertTrue([myReport isEqualTo:values]); - [reportExpectation fulfill]; - } - subscriptionEstablished:^{ - [establishExpectation fulfill]; - }]; - }]; + getDevice:myNodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Subscribing..."); + [device subscribeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + minInterval:myMinInterval + maxInterval:myMaxInterval + params:nil + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { + NSLog(@"Report value: %@", values); + XCTAssertNotNil(values); + XCTAssertNil(error); + XCTAssertTrue([myReport isEqualTo:values]); + [reportExpectation fulfill]; + } + subscriptionEstablished:^{ + [establishExpectation fulfill]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, establishExpectation, nil] timeout:kTimeoutInSeconds]; @@ -1201,14 +1201,14 @@ - (void)testBadlyFormattedReport // Deregister report handler _xpcDisconnectExpectation.inverted = NO; [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + }]; + }]; // Wait for disconnection [self waitForExpectations:@[ _xpcDisconnectExpectation, stopExpectation ] timeout:kTimeoutInSeconds]; @@ -1253,30 +1253,30 @@ - (void)testReportWithUnrelatedEndpointId _xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"]; [_remoteDeviceController - getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Subscribing..."); - [device subscribeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - minInterval:myMinInterval - maxInterval:myMaxInterval - params:nil - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { - NSLog(@"Report value: %@", values); - XCTAssertNotNil(values); - XCTAssertNil(error); - XCTAssertTrue([myReport isEqualTo:values]); - [reportExpectation fulfill]; - } - subscriptionEstablished:^{ - [establishExpectation fulfill]; - }]; - }]; + getDevice:myNodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Subscribing..."); + [device subscribeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + minInterval:myMinInterval + maxInterval:myMaxInterval + params:nil + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { + NSLog(@"Report value: %@", values); + XCTAssertNotNil(values); + XCTAssertNil(error); + XCTAssertTrue([myReport isEqualTo:values]); + [reportExpectation fulfill]; + } + subscriptionEstablished:^{ + [establishExpectation fulfill]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, establishExpectation, nil] timeout:kTimeoutInSeconds]; @@ -1317,14 +1317,14 @@ - (void)testReportWithUnrelatedEndpointId // Deregister report handler [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + }]; + }]; // Wait for disconnection [self waitForExpectations:@[ _xpcDisconnectExpectation, stopExpectation ] timeout:kTimeoutInSeconds]; @@ -1369,30 +1369,30 @@ - (void)testReportWithUnrelatedClusterId _xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"]; [_remoteDeviceController - getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Subscribing..."); - [device subscribeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - minInterval:myMinInterval - maxInterval:myMaxInterval - params:nil - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { - NSLog(@"Report value: %@", values); - XCTAssertNotNil(values); - XCTAssertNil(error); - XCTAssertTrue([myReport isEqualTo:values]); - [reportExpectation fulfill]; - } - subscriptionEstablished:^{ - [establishExpectation fulfill]; - }]; - }]; + getDevice:myNodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Subscribing..."); + [device subscribeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + minInterval:myMinInterval + maxInterval:myMaxInterval + params:nil + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { + NSLog(@"Report value: %@", values); + XCTAssertNotNil(values); + XCTAssertNil(error); + XCTAssertTrue([myReport isEqualTo:values]); + [reportExpectation fulfill]; + } + subscriptionEstablished:^{ + [establishExpectation fulfill]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, establishExpectation, nil] timeout:kTimeoutInSeconds]; @@ -1433,14 +1433,14 @@ - (void)testReportWithUnrelatedClusterId // Deregister report handler [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + }]; + }]; // Wait for disconnection [self waitForExpectations:@[ _xpcDisconnectExpectation, stopExpectation ] timeout:kTimeoutInSeconds]; @@ -1485,30 +1485,30 @@ - (void)testReportWithUnrelatedAttributeId _xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"]; [_remoteDeviceController - getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Subscribing..."); - [device subscribeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - minInterval:myMinInterval - maxInterval:myMaxInterval - params:nil - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { - NSLog(@"Report value: %@", values); - XCTAssertNotNil(values); - XCTAssertNil(error); - XCTAssertTrue([myReport isEqualTo:values]); - [reportExpectation fulfill]; - } - subscriptionEstablished:^{ - [establishExpectation fulfill]; - }]; - }]; + getDevice:myNodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Subscribing..."); + [device subscribeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + minInterval:myMinInterval + maxInterval:myMaxInterval + params:nil + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { + NSLog(@"Report value: %@", values); + XCTAssertNotNil(values); + XCTAssertNil(error); + XCTAssertTrue([myReport isEqualTo:values]); + [reportExpectation fulfill]; + } + subscriptionEstablished:^{ + [establishExpectation fulfill]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, establishExpectation, nil] timeout:kTimeoutInSeconds]; @@ -1549,14 +1549,14 @@ - (void)testReportWithUnrelatedAttributeId // Deregister report handler [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + }]; + }]; // Wait for disconnection [self waitForExpectations:@[ _xpcDisconnectExpectation, stopExpectation ] timeout:kTimeoutInSeconds]; @@ -1601,30 +1601,30 @@ - (void)testReportWithUnrelatedNode _xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"]; [_remoteDeviceController - getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Subscribing..."); - [device subscribeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - minInterval:myMinInterval - maxInterval:myMaxInterval - params:nil - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { - NSLog(@"Report value: %@", values); - XCTAssertNotNil(values); - XCTAssertNil(error); - XCTAssertTrue([myReport isEqualTo:values]); - [reportExpectation fulfill]; - } - subscriptionEstablished:^{ - [establishExpectation fulfill]; - }]; - }]; + getDevice:myNodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Subscribing..."); + [device subscribeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + minInterval:myMinInterval + maxInterval:myMaxInterval + params:nil + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { + NSLog(@"Report value: %@", values); + XCTAssertNotNil(values); + XCTAssertNil(error); + XCTAssertTrue([myReport isEqualTo:values]); + [reportExpectation fulfill]; + } + subscriptionEstablished:^{ + [establishExpectation fulfill]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, establishExpectation, nil] timeout:kTimeoutInSeconds]; @@ -1665,14 +1665,14 @@ - (void)testReportWithUnrelatedNode // Deregister report handler [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + }]; + }]; // Wait for disconnection [self waitForExpectations:@[ _xpcDisconnectExpectation, stopExpectation ] timeout:kTimeoutInSeconds]; @@ -1716,30 +1716,30 @@ - (void)testSubscribeMultiEndpoints _xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"]; [_remoteDeviceController - getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Subscribing..."); - [device subscribeAttributeWithEndpointId:nil - clusterId:myClusterId - attributeId:myAttributeId - minInterval:myMinInterval - maxInterval:myMaxInterval - params:nil - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { - NSLog(@"Report value: %@", values); - XCTAssertNotNil(values); - XCTAssertNil(error); - XCTAssertTrue([myReport isEqualTo:values]); - [reportExpectation fulfill]; - } - subscriptionEstablished:^{ - [establishExpectation fulfill]; - }]; - }]; + getDevice:myNodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Subscribing..."); + [device subscribeAttributeWithEndpointId:nil + clusterId:myClusterId + attributeId:myAttributeId + minInterval:myMinInterval + maxInterval:myMaxInterval + params:nil + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { + NSLog(@"Report value: %@", values); + XCTAssertNotNil(values); + XCTAssertNil(error); + XCTAssertTrue([myReport isEqualTo:values]); + [reportExpectation fulfill]; + } + subscriptionEstablished:^{ + [establishExpectation fulfill]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, establishExpectation, nil] timeout:kTimeoutInSeconds]; @@ -1780,14 +1780,14 @@ - (void)testSubscribeMultiEndpoints // Deregister report handler [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + }]; + }]; // Wait for disconnection [self waitForExpectations:@[ _xpcDisconnectExpectation, stopExpectation ] timeout:kTimeoutInSeconds]; @@ -1831,30 +1831,30 @@ - (void)testSubscribeMultiClusters _xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"]; [_remoteDeviceController - getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Subscribing..."); - [device subscribeAttributeWithEndpointId:myEndpointId - clusterId:nil - attributeId:myAttributeId - minInterval:myMinInterval - maxInterval:myMaxInterval - params:nil - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { - NSLog(@"Report value: %@", values); - XCTAssertNotNil(values); - XCTAssertNil(error); - XCTAssertTrue([myReport isEqualTo:values]); - [reportExpectation fulfill]; - } - subscriptionEstablished:^{ - [establishExpectation fulfill]; - }]; - }]; + getDevice:myNodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Subscribing..."); + [device subscribeAttributeWithEndpointId:myEndpointId + clusterId:nil + attributeId:myAttributeId + minInterval:myMinInterval + maxInterval:myMaxInterval + params:nil + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { + NSLog(@"Report value: %@", values); + XCTAssertNotNil(values); + XCTAssertNil(error); + XCTAssertTrue([myReport isEqualTo:values]); + [reportExpectation fulfill]; + } + subscriptionEstablished:^{ + [establishExpectation fulfill]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, establishExpectation, nil] timeout:kTimeoutInSeconds]; @@ -1895,14 +1895,14 @@ - (void)testSubscribeMultiClusters // Deregister report handler [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + }]; + }]; // Wait for disconnection [self waitForExpectations:@[ _xpcDisconnectExpectation, stopExpectation ] timeout:kTimeoutInSeconds]; @@ -1946,30 +1946,30 @@ - (void)testSubscribeMultiAttributes _xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"]; [_remoteDeviceController - getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Subscribing..."); - [device subscribeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:nil - minInterval:myMinInterval - maxInterval:myMaxInterval - params:nil - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { - NSLog(@"Report value: %@", values); - XCTAssertNotNil(values); - XCTAssertNil(error); - XCTAssertTrue([myReport isEqualTo:values]); - [reportExpectation fulfill]; - } - subscriptionEstablished:^{ - [establishExpectation fulfill]; - }]; - }]; + getDevice:myNodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Subscribing..."); + [device subscribeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:nil + minInterval:myMinInterval + maxInterval:myMaxInterval + params:nil + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { + NSLog(@"Report value: %@", values); + XCTAssertNotNil(values); + XCTAssertNil(error); + XCTAssertTrue([myReport isEqualTo:values]); + [reportExpectation fulfill]; + } + subscriptionEstablished:^{ + [establishExpectation fulfill]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, establishExpectation, nil] timeout:kTimeoutInSeconds]; @@ -2010,14 +2010,14 @@ - (void)testSubscribeMultiAttributes // Deregister report handler [_remoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + }]; + }]; // Wait for disconnection [self waitForExpectations:@[ _xpcDisconnectExpectation, stopExpectation ] timeout:kTimeoutInSeconds]; @@ -2072,30 +2072,30 @@ - (void)testMutiSubscriptions callExpectation = [self expectationWithDescription:[NSString stringWithFormat:@"XPC call (%d) received", i]]; establishExpectation = [self expectationWithDescription:[NSString stringWithFormat:@"Established (%d) called", i]]; [_remoteDeviceController - getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Subscribing..."); - [device subscribeAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - minInterval:myMinInterval - maxInterval:myMaxInterval - params:nil - clientQueue:dispatch_get_main_queue() - reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { - NSLog(@"Subscriber [%d] report value: %@", i, values); - XCTAssertNotNil(values); - XCTAssertNil(error); - XCTAssertTrue([myReports[i] isEqualTo:values]); - [reportExpectations[i] fulfill]; - } - subscriptionEstablished:^{ - [establishExpectation fulfill]; - }]; - }]; + getDevice:myNodeId + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Subscribing..."); + [device subscribeAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + minInterval:myMinInterval + maxInterval:myMaxInterval + params:nil + clientQueue:dispatch_get_main_queue() + reportHandler:^(NSArray *> * _Nullable values, NSError * _Nullable error) { + NSLog(@"Subscriber [%d] report value: %@", i, values); + XCTAssertNotNil(values); + XCTAssertNil(error); + XCTAssertTrue([myReports[i] isEqualTo:values]); + [reportExpectations[i] fulfill]; + } + subscriptionEstablished:^{ + [establishExpectation fulfill]; + }]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, establishExpectation, nil] timeout:kTimeoutInSeconds]; } @@ -2147,15 +2147,15 @@ - (void)testMutiSubscriptions // Deregister report handler for first subscriber __auto_type deregisterExpectation = [self expectationWithDescription:@"First subscriber deregistered"]; [_remoteDeviceController getDevice:nodeToStop - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - [deregisterExpectation fulfill]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + [deregisterExpectation fulfill]; + }]; + }]; [self waitForExpectations:@[ stopExpectation, deregisterExpectation ] timeout:kTimeoutInSeconds]; @@ -2205,15 +2205,15 @@ - (void)testMutiSubscriptions // Deregister report handler for second subscriber __auto_type secondDeregisterExpectation = [self expectationWithDescription:@"Second subscriber deregistered"]; [_remoteDeviceController getDevice:nodeToStop - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - NSLog(@"Device acquired. Deregistering..."); - [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() - completion:^{ - NSLog(@"Deregistered"); - [secondDeregisterExpectation fulfill]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + NSLog(@"Device acquired. Deregistering..."); + [device deregisterReportHandlersWithClientQueue:dispatch_get_main_queue() + completion:^{ + NSLog(@"Deregistered"); + [secondDeregisterExpectation fulfill]; + }]; + }]; // Wait for deregistration and disconnection [self waitForExpectations:@[ secondDeregisterExpectation, _xpcDisconnectExpectation, stopExpectation ] @@ -2275,12 +2275,12 @@ - (void)testAnySharedRemoteController __auto_type deviceAcquired = [self expectationWithDescription:@"Connected device was acquired"]; [unspecifiedRemoteDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - [deviceAcquired fulfill]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + [deviceAcquired fulfill]; + }]; [self waitForExpectations:[NSArray arrayWithObjects:anySharedRemoteControllerCallExpectation, deviceAcquired, nil] timeout:kTimeoutInSeconds]; @@ -2535,23 +2535,23 @@ - (void)testXPCConnectionFailure }]; [failingDeviceController getDevice:myNodeId - queue:dispatch_get_main_queue() - completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { - XCTAssertNotNil(device); - XCTAssertNil(error); - NSLog(@"Device acquired. Reading..."); - [device readAttributeWithEndpointId:myEndpointId - clusterId:myClusterId - attributeId:myAttributeId - params:nil - clientQueue:dispatch_get_main_queue() - completion:^(id _Nullable value, NSError * _Nullable error) { - NSLog(@"Read value: %@", value); - XCTAssertNil(value); - XCTAssertNotNil(error); - [responseExpectation fulfill]; - }]; - }]; + queue:dispatch_get_main_queue() + completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) { + XCTAssertNotNil(device); + XCTAssertNil(error); + NSLog(@"Device acquired. Reading..."); + [device readAttributeWithEndpointId:myEndpointId + clusterId:myClusterId + attributeId:myAttributeId + params:nil + clientQueue:dispatch_get_main_queue() + completion:^(id _Nullable value, NSError * _Nullable error) { + NSLog(@"Read value: %@", value); + XCTAssertNil(value); + XCTAssertNotNil(error); + [responseExpectation fulfill]; + }]; + }]; [self waitForExpectations:@[ responseExpectation ] timeout:kTimeoutInSeconds]; }