@@ -758,7 +758,7 @@ - (void)test004_Subscribe
758
758
MTRBaseDevice * device = GetConnectedDevice ();
759
759
dispatch_queue_t queue = dispatch_get_main_queue ();
760
760
761
- __auto_type * params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(2 ) maxInterval: @(10 )];
761
+ __auto_type * params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(0 ) maxInterval: @(10 )];
762
762
[device subscribeToAttributesWithEndpointID: @1
763
763
clusterID: @6
764
764
attributeID: @0
@@ -958,7 +958,7 @@ - (void)test008_SubscribeFailure
958
958
MTRBaseDevice * device = GetConnectedDevice ();
959
959
dispatch_queue_t queue = dispatch_get_main_queue ();
960
960
961
- __auto_type * params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(2 ) maxInterval: @(10 )];
961
+ __auto_type * params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(0 ) maxInterval: @(10 )];
962
962
params.resubscribeAutomatically = NO ;
963
963
[device subscribeToAttributesWithEndpointID: @10000
964
964
clusterID: @6
@@ -1039,7 +1039,7 @@ - (void)test010_SubscribeWithNoParams
1039
1039
1040
1040
// Subscribe
1041
1041
XCTestExpectation * subscribeExpectation = [self expectationWithDescription: @" subscribe OnOff attribute" ];
1042
- __auto_type * params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(2 ) maxInterval: @(10 )];
1042
+ __auto_type * params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(0 ) maxInterval: @(10 )];
1043
1043
[device subscribeToAttributesWithEndpointID: @1
1044
1044
clusterID: @6
1045
1045
attributeID: @0
@@ -1064,7 +1064,7 @@ - (void)test010_SubscribeWithNoParams
1064
1064
1065
1065
// Setup 2nd subscriber
1066
1066
subscribeExpectation = [self expectationWithDescription: @" subscribe CurrentLevel attribute" ];
1067
- params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(2 ) maxInterval: @(10 )];
1067
+ params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(0 ) maxInterval: @(10 )];
1068
1068
[device subscribeToAttributesWithEndpointID: @1
1069
1069
clusterID: @8
1070
1070
attributeID: @0
@@ -1212,7 +1212,7 @@ - (void)test011_SubscribeWithParams
1212
1212
1213
1213
// Subscribe
1214
1214
XCTestExpectation * subscribeExpectation = [self expectationWithDescription: @" subscribe OnOff attribute" ];
1215
- __auto_type * params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(2 ) maxInterval: @(10 )];
1215
+ __auto_type * params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(0 ) maxInterval: @(10 )];
1216
1216
[device subscribeToAttributesWithEndpointID: @1
1217
1217
clusterID: @6
1218
1218
attributeID: @0
@@ -1236,7 +1236,7 @@ - (void)test011_SubscribeWithParams
1236
1236
[self waitForExpectations: @[ subscribeExpectation ] timeout: kTimeoutInSeconds ];
1237
1237
1238
1238
// Setup 2nd subscriber
1239
- MTRSubscribeParams * myParams = [[MTRSubscribeParams alloc ] initWithMinInterval: @(2 ) maxInterval: @(10 )];
1239
+ MTRSubscribeParams * myParams = [[MTRSubscribeParams alloc ] initWithMinInterval: @(0 ) maxInterval: @(10 )];
1240
1240
myParams.replaceExistingSubscriptions = YES ;
1241
1241
subscribeExpectation = [self expectationWithDescription: @" subscribe CurrentLevel attribute" ];
1242
1242
[device subscribeToAttributesWithEndpointID: @1
@@ -1390,10 +1390,31 @@ - (void)test012_SubscribeKeepingPreviousSubscription
1390
1390
1391
1391
__block void (^firstReportHandler)(id _Nullable values, NSError * _Nullable error) = nil ;
1392
1392
__block void (^secondReportHandler)(id _Nullable values, NSError * _Nullable error) = nil ;
1393
+ // Depending on how this test is run (alone or after other tests), we might
1394
+ // be either in the "On" or "Off" state when we start. Track that, so we
1395
+ // can ensure we're in the "Off" state correctly later.
1396
+ __block BOOL initialOnOffState;
1397
+
1398
+ XCTestExpectation * initialOnOffReportExpectation = [self expectationWithDescription: @" initial OnOff report expectation" ];
1399
+ firstReportHandler = ^(id _Nullable values, NSError * _Nullable error) {
1400
+ XCTAssertNil (error);
1401
+
1402
+ XCTAssertTrue ([values isKindOfClass: [NSArray class ]]);
1403
+ NSDictionary * result = values[0 ];
1404
+ MTRAttributePath * path = result[@" attributePath" ];
1405
+ XCTAssertEqual ([path.endpoint unsignedIntegerValue ], 1 );
1406
+ XCTAssertEqual ([path.cluster unsignedIntegerValue ], 6 );
1407
+ XCTAssertEqual ([path.attribute unsignedIntegerValue ], 0 );
1408
+ XCTAssertTrue ([result[@" data" ] isKindOfClass: [NSDictionary class ]]);
1409
+ XCTAssertTrue ([result[@" data" ][@" type" ] isEqualToString: @" Boolean" ]);
1410
+ initialOnOffState = [result[@" data" ][@" value" ] boolValue ];
1411
+
1412
+ [initialOnOffReportExpectation fulfill ];
1413
+ };
1393
1414
1394
1415
// Subscribe
1395
1416
XCTestExpectation * subscribeExpectation = [self expectationWithDescription: @" subscribe OnOff attribute" ];
1396
- __auto_type * params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(2 ) maxInterval: @(10 )];
1417
+ __auto_type * params = [[MTRSubscribeParams alloc ] initWithMinInterval: @(0 ) maxInterval: @(10 )];
1397
1418
[device subscribeToAttributesWithEndpointID: @1
1398
1419
clusterID: @6
1399
1420
attributeID: @0
@@ -1414,11 +1435,11 @@ - (void)test012_SubscribeKeepingPreviousSubscription
1414
1435
[subscribeExpectation fulfill ];
1415
1436
}];
1416
1437
1417
- [self waitForExpectations: @[ subscribeExpectation ] timeout: kTimeoutInSeconds ];
1438
+ [self waitForExpectations: @[ subscribeExpectation, initialOnOffReportExpectation ] timeout: kTimeoutInSeconds ];
1418
1439
1419
1440
// Setup 2nd subscriber
1420
1441
subscribeExpectation = [self expectationWithDescription: @" subscribe CurrentLevel attribute" ];
1421
- MTRSubscribeParams * myParams = [[MTRSubscribeParams alloc ] initWithMinInterval: @(2 ) maxInterval: @(10 )];
1442
+ MTRSubscribeParams * myParams = [[MTRSubscribeParams alloc ] initWithMinInterval: @(0 ) maxInterval: @(10 )];
1422
1443
myParams.replaceExistingSubscriptions = NO ;
1423
1444
[device subscribeToAttributesWithEndpointID: @1
1424
1445
clusterID: @8
@@ -1443,7 +1464,31 @@ - (void)test012_SubscribeKeepingPreviousSubscription
1443
1464
// Wait till establishment
1444
1465
[self waitForExpectations: @[ subscribeExpectation ] timeout: kTimeoutInSeconds ];
1445
1466
1446
- // Send command to clear attribute state
1467
+ // If we were initially on, set up expectations for report that we have been
1468
+ // turned off, so we make sure that comes through before we do the rest of
1469
+ // the test.
1470
+ XCTestExpectation * offReportExpectation;
1471
+ if (initialOnOffState == YES ) {
1472
+ offReportExpectation = [self expectationWithDescription: @" OnOff attribute has become false." ];
1473
+ firstReportHandler = ^(id _Nullable values, NSError * _Nullable error) {
1474
+ XCTAssertNil (error);
1475
+
1476
+ {
1477
+ XCTAssertTrue ([values isKindOfClass: [NSArray class ]]);
1478
+ NSDictionary * result = values[0 ];
1479
+ MTRAttributePath * path = result[@" attributePath" ];
1480
+ XCTAssertEqual ([path.endpoint unsignedIntegerValue ], 1 );
1481
+ XCTAssertEqual ([path.cluster unsignedIntegerValue ], 6 );
1482
+ XCTAssertEqual ([path.attribute unsignedIntegerValue ], 0 );
1483
+ XCTAssertTrue ([result[@" data" ] isKindOfClass: [NSDictionary class ]]);
1484
+ XCTAssertTrue ([result[@" data" ][@" type" ] isEqualToString: @" Boolean" ]);
1485
+ XCTAssertEqual ([result[@" data" ][@" value" ] boolValue ], NO );
1486
+ }
1487
+ [offReportExpectation fulfill ];
1488
+ };
1489
+ }
1490
+
1491
+ // Ensure that we are in the "off" state.
1447
1492
XCTestExpectation * clearCommandExpectation = [self expectationWithDescription: @" Clearing command invoked" ];
1448
1493
[device invokeCommandWithEndpointID: @1
1449
1494
clusterID: @6
@@ -1452,7 +1497,7 @@ - (void)test012_SubscribeKeepingPreviousSubscription
1452
1497
timedInvokeTimeout: nil
1453
1498
queue: queue
1454
1499
completion: ^(id _Nullable values, NSError * _Nullable error) {
1455
- NSLog (@" invoke command: On values: %@ , error: %@ " , values, error);
1500
+ NSLog (@" invoke command: Off values: %@ , error: %@ " , values, error);
1456
1501
1457
1502
XCTAssertNil (error);
1458
1503
@@ -1471,6 +1516,9 @@ - (void)test012_SubscribeKeepingPreviousSubscription
1471
1516
[clearCommandExpectation fulfill ];
1472
1517
}];
1473
1518
[self waitForExpectations: @[ clearCommandExpectation ] timeout: kTimeoutInSeconds ];
1519
+ if (offReportExpectation) {
1520
+ [self waitForExpectations: @[ offReportExpectation ] timeout: kTimeoutInSeconds ];
1521
+ }
1474
1522
1475
1523
// Set up expectations for report
1476
1524
XCTestExpectation * reportExpectation = [self expectationWithDescription: @" The 1st subscriber received OnOff attribute report" ];
@@ -1622,7 +1670,7 @@ - (void)test013_TimedWriteAttribute
1622
1670
// subscribe, which should get the new value at the timeout
1623
1671
expectation = [self expectationWithDescription:@"Subscribed"];
1624
1672
__block void (^reportHandler)(id _Nullable values, NSError * _Nullable error);
1625
- __auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2 ) maxInterval:@(10)];
1673
+ __auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(0 ) maxInterval:@(10)];
1626
1674
[device subscribeToAttributesWithEndpointID:@1
1627
1675
clusterID:@8
1628
1676
attributeID:@17
0 commit comments