|
111 | 111 | {
|
112 | 112 | dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip-tool.command", DISPATCH_QUEUE_SERIAL);
|
113 | 113 | MTRDeviceController * commissioner = CurrentCommissioner();
|
114 |
| - [commissioner getBaseDevice:mNodeId |
115 |
| - queue:callbackQueue |
116 |
| - completionHandler:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) { |
117 |
| - CHIP_ERROR err = CHIP_NO_ERROR; |
118 |
| - if (error) { |
119 |
| - err = MTRErrorToCHIPErrorCode(error); |
120 |
| - LogNSError("Error: ", error); |
121 |
| - SetCommandExitStatus(err); |
122 |
| - } else if (device == nil) { |
123 |
| - ChipLogError(chipTool, "Error: %s", chip::ErrorStr(CHIP_ERROR_INTERNAL)); |
124 |
| - SetCommandExitStatus(CHIP_ERROR_INTERNAL); |
125 |
| - } else { |
126 |
| - ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId); |
127 |
| - MTRBaseClusterOperationalCredentials * opCredsCluster = |
128 |
| - [[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:callbackQueue]; |
129 |
| - [opCredsCluster readAttributeCurrentFabricIndexWithCompletionHandler:^( |
130 |
| - NSNumber * _Nullable value, NSError * _Nullable readError) { |
131 |
| - if (readError) { |
132 |
| - CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError); |
133 |
| - LogNSError("Failed to get current fabric: ", readError); |
134 |
| - SetCommandExitStatus(readErr); |
135 |
| - return; |
136 |
| - } |
137 |
| - MTROperationalCredentialsClusterRemoveFabricParams * params = |
138 |
| - [[MTROperationalCredentialsClusterRemoveFabricParams alloc] init]; |
139 |
| - params.fabricIndex = value; |
140 |
| - [opCredsCluster |
141 |
| - removeFabricWithParams:params |
142 |
| - completionHandler:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data, |
143 |
| - NSError * _Nullable removeError) { |
144 |
| - CHIP_ERROR removeErr = CHIP_NO_ERROR; |
145 |
| - if (removeError) { |
146 |
| - removeErr = MTRErrorToCHIPErrorCode(removeError); |
147 |
| - LogNSError("Failed to remove current fabric: ", removeError); |
148 |
| - } else { |
149 |
| - ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId); |
150 |
| - } |
151 |
| - SetCommandExitStatus(removeErr); |
152 |
| - }]; |
153 |
| - }]; |
154 |
| - } |
155 |
| - }]; |
| 114 | + [commissioner |
| 115 | + getBaseDevice:mNodeId |
| 116 | + queue:callbackQueue |
| 117 | + completion:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) { |
| 118 | + CHIP_ERROR err = CHIP_NO_ERROR; |
| 119 | + if (error) { |
| 120 | + err = MTRErrorToCHIPErrorCode(error); |
| 121 | + LogNSError("Error: ", error); |
| 122 | + SetCommandExitStatus(err); |
| 123 | + } else if (device == nil) { |
| 124 | + ChipLogError(chipTool, "Error: %s", chip::ErrorStr(CHIP_ERROR_INTERNAL)); |
| 125 | + SetCommandExitStatus(CHIP_ERROR_INTERNAL); |
| 126 | + } else { |
| 127 | + ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId); |
| 128 | + MTRBaseClusterOperationalCredentials * opCredsCluster = |
| 129 | + [[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:callbackQueue]; |
| 130 | + [opCredsCluster |
| 131 | + readAttributeCurrentFabricIndexWithCompletion:^(NSNumber * _Nullable value, NSError * _Nullable readError) { |
| 132 | + if (readError) { |
| 133 | + CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError); |
| 134 | + LogNSError("Failed to get current fabric: ", readError); |
| 135 | + SetCommandExitStatus(readErr); |
| 136 | + return; |
| 137 | + } |
| 138 | + MTROperationalCredentialsClusterRemoveFabricParams * params = |
| 139 | + [[MTROperationalCredentialsClusterRemoveFabricParams alloc] init]; |
| 140 | + params.fabricIndex = value; |
| 141 | + [opCredsCluster |
| 142 | + removeFabricWithParams:params |
| 143 | + completion:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data, |
| 144 | + NSError * _Nullable removeError) { |
| 145 | + CHIP_ERROR removeErr = CHIP_NO_ERROR; |
| 146 | + if (removeError) { |
| 147 | + removeErr = MTRErrorToCHIPErrorCode(removeError); |
| 148 | + LogNSError("Failed to remove current fabric: ", removeError); |
| 149 | + } else { |
| 150 | + ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId); |
| 151 | + } |
| 152 | + SetCommandExitStatus(removeErr); |
| 153 | + }]; |
| 154 | + }]; |
| 155 | + } |
| 156 | + }]; |
156 | 157 | }
|
0 commit comments