@@ -1813,6 +1813,58 @@ - (void)test900_SubscribeClusterStateCache
1813
1813
#if !MANUAL_INDIVIDUAL_TEST
1814
1814
- (void )test999_TearDown
1815
1815
{
1816
+ // Put the device back in the state we found it: open commissioning window, no fabrics commissioned.
1817
+ MTRBaseDevice * device = [MTRBaseDevice deviceWithNodeID: @(kDeviceId ) controller: sController ];
1818
+ dispatch_queue_t queue = dispatch_get_main_queue ();
1819
+
1820
+ // Get our current fabric index, for later deletion.
1821
+ XCTestExpectation * readFabricIndexExpectation = [self expectationWithDescription: @" Fabric index read" ];
1822
+
1823
+ __block NSNumber * fabricIndex;
1824
+ __auto_type * opCredsCluster = [[MTRBaseClusterOperationalCredentials alloc ] initWithDevice: device endpoint: @(0 ) queue: queue];
1825
+ [opCredsCluster readAttributeCurrentFabricIndexWithCompletion: ^(NSNumber * _Nullable value, NSError * _Nullable readError) {
1826
+ XCTAssertNil (readError);
1827
+ XCTAssertNotNil (value);
1828
+ fabricIndex = value;
1829
+ [readFabricIndexExpectation fulfill ];
1830
+ }];
1831
+
1832
+ [self waitForExpectations: @[ readFabricIndexExpectation ] timeout: kTimeoutInSeconds ];
1833
+
1834
+ // Open a commissioning window.
1835
+ XCTestExpectation * openCommissioningWindowExpectation = [self expectationWithDescription: @" Commissioning window opened" ];
1836
+
1837
+ __auto_type * adminCommissioningCluster = [[MTRBaseClusterAdministratorCommissioning alloc ] initWithDevice: device
1838
+ endpoint: @(0 )
1839
+ queue: queue];
1840
+ __auto_type * openWindowParams = [[MTRAdministratorCommissioningClusterOpenBasicCommissioningWindowParams alloc ] init ];
1841
+ openWindowParams.commissioningTimeout = @(900 );
1842
+ openWindowParams.timedInvokeTimeoutMs = @(50000 );
1843
+ [adminCommissioningCluster openBasicCommissioningWindowWithParams: openWindowParams
1844
+ completion: ^(NSError * _Nullable error) {
1845
+ XCTAssertNil (error);
1846
+ [openCommissioningWindowExpectation fulfill ];
1847
+ }];
1848
+
1849
+ [self waitForExpectations: @[ openCommissioningWindowExpectation ] timeout: kTimeoutInSeconds ];
1850
+
1851
+ // Remove our fabric from the device.
1852
+ XCTestExpectation * removeFabricExpectation = [self expectationWithDescription: @" Fabric removed" ];
1853
+
1854
+ __auto_type * removeParams = [[MTROperationalCredentialsClusterRemoveFabricParams alloc ] init ];
1855
+ removeParams.fabricIndex = fabricIndex;
1856
+
1857
+ [opCredsCluster removeFabricWithParams: removeParams
1858
+ completion: ^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
1859
+ NSError * _Nullable removeError) {
1860
+ XCTAssertNil (removeError);
1861
+ XCTAssertNotNil (data);
1862
+ XCTAssertEqualObjects (data.statusCode , @(0 ));
1863
+ [removeFabricExpectation fulfill ];
1864
+ }];
1865
+
1866
+ [self waitForExpectations: @[ removeFabricExpectation ] timeout: kTimeoutInSeconds ];
1867
+
1816
1868
[self shutdownStack ];
1817
1869
}
1818
1870
#endif
0 commit comments