@@ -2974,6 +2974,7 @@ - (void)test031_MTRDeviceAttributeCacheLocalTestStorage
2974
2974
}
2975
2975
NSUInteger storedAttributeCountDifferenceFromMTRDeviceReport = dataStoreAttributeCountAfterSecondSubscription - attributesReportedWithSecondSubscription;
2976
2976
XCTAssertTrue (storedAttributeCountDifferenceFromMTRDeviceReport > 300 );
2977
+ [sController removeDevice: device];
2977
2978
}
2978
2979
2979
2980
- (void )test032_MTRPathClassesEncoding
@@ -3020,6 +3021,115 @@ - (void)test032_MTRPathClassesEncoding
3020
3021
XCTAssertEqualObjects (originalCommandPath, decodedCommandPath);
3021
3022
}
3022
3023
3024
+ #ifdef DEBUG
3025
+ - (void )test033_TestMTRDeviceDeviceConfigurationChanged
3026
+ {
3027
+ // Ensure the test starts with clean slate.
3028
+ [sController .controllerDataStore clearAllStoredClusterData ];
3029
+ NSDictionary * storedClusterDataAfterClear = [sController .controllerDataStore getStoredClusterDataForNodeID: @(kDeviceId )];
3030
+ XCTAssertEqual (storedClusterDataAfterClear.count , 0 );
3031
+
3032
+ __auto_type * device = [MTRDevice deviceWithNodeID: kDeviceId deviceController: sController ];
3033
+ dispatch_queue_t queue = dispatch_get_main_queue ();
3034
+
3035
+ // Check if subscription is set up and initial reports are received.
3036
+ XCTestExpectation * subscriptionExpectation = [self expectationWithDescription: @" Subscription has been set up" ];
3037
+ XCTestExpectation * gotInitialReportsExpectation = [self expectationWithDescription: @" Initial Attribute and Event reports have been received" ];
3038
+
3039
+ __auto_type * delegate = [[MTRDeviceTestDelegate alloc ] init ];
3040
+ delegate.onReachable = ^() {
3041
+ [subscriptionExpectation fulfill ];
3042
+ };
3043
+
3044
+ delegate.onReportEnd = ^() {
3045
+ [gotInitialReportsExpectation fulfill ];
3046
+ };
3047
+
3048
+ [device setDelegate: delegate queue: queue];
3049
+
3050
+ // Wait for subscription set up and intitial reports received.
3051
+ [self waitForExpectations: @[ subscriptionExpectation, gotInitialReportsExpectation, ] timeout: 60 ];
3052
+
3053
+ XCTestExpectation * gotAttributeReportExpectation = [self expectationWithDescription: @" Attribute report has been received" ];
3054
+ XCTestExpectation * gotAttributeReportEndExpectation = [self expectationWithDescription: @" Attribute report has ended" ];
3055
+ XCTestExpectation * deviceConfigurationChangedExpectation = [self expectationWithDescription: @" Device configuration changed was receieved" ];
3056
+ __block unsigned attributeReportsReceived = 0 ;
3057
+ delegate.onAttributeDataReceived = ^(NSArray <NSDictionary <NSString *, id > *> * attributeReport) {
3058
+ attributeReportsReceived += attributeReport.count ;
3059
+ XCTAssert (attributeReportsReceived > 0 );
3060
+ for (NSDictionary <NSString *, id > * attributeDict in attributeReport) {
3061
+ MTRAttributePath * attributePath = attributeDict[MTRAttributePathKey];
3062
+ XCTAssert (attributePath != nil );
3063
+
3064
+ XCTAssert (attributePath.cluster .unsignedLongValue == MTRClusterDescriptorID);
3065
+ XCTAssert (attributePath.attribute .unsignedLongValue == MTRClusterDescriptorAttributePartsListID);
3066
+
3067
+ NSDictionary * dataValue = attributeDict[MTRDataKey];
3068
+ XCTAssert (dataValue != nil );
3069
+ NSArray <NSNumber *> * partsList = dataValue[MTRValueKey];
3070
+ XCTAssert ([partsList isEqual: (@[
3071
+ @{
3072
+ MTRDataKey : @ {
3073
+ MTRTypeKey : MTRUnsignedIntegerValueType,
3074
+ MTRValueKey : @1 ,
3075
+ }
3076
+ },
3077
+ @{
3078
+ MTRDataKey : @ {
3079
+ MTRTypeKey : MTRUnsignedIntegerValueType,
3080
+ MTRValueKey : @2 ,
3081
+ }
3082
+ },
3083
+ @{
3084
+ MTRDataKey : @ {
3085
+ MTRTypeKey : MTRUnsignedIntegerValueType,
3086
+ MTRValueKey : @3 ,
3087
+ }
3088
+ },
3089
+ ])]);
3090
+ [gotAttributeReportExpectation fulfill ];
3091
+ }
3092
+ };
3093
+
3094
+ delegate.onReportEnd = ^() {
3095
+ [gotAttributeReportEndExpectation fulfill ];
3096
+ };
3097
+
3098
+ delegate.onDeviceConfigurationChanged = ^() {
3099
+ [deviceConfigurationChangedExpectation fulfill ];
3100
+ };
3101
+
3102
+ // Inject the attribute report with parts list changed.
3103
+ [device unitTestInjectAttributeReport: @[ @{
3104
+ MTRAttributePathKey : [MTRAttributePath attributePathWithEndpointID: @(0 ) clusterID: @(0x001D ) attributeID: @(3 )],
3105
+ MTRDataKey : @{
3106
+ MTRTypeKey : MTRArrayValueType,
3107
+ MTRValueKey : @[
3108
+ @{
3109
+ MTRDataKey : @ {
3110
+ MTRTypeKey : MTRUnsignedIntegerValueType,
3111
+ MTRValueKey : @1 ,
3112
+ }
3113
+ },
3114
+ @{
3115
+ MTRDataKey : @ {
3116
+ MTRTypeKey : MTRUnsignedIntegerValueType,
3117
+ MTRValueKey : @2 ,
3118
+ }
3119
+ },
3120
+ @{
3121
+ MTRDataKey : @ {
3122
+ MTRTypeKey : MTRUnsignedIntegerValueType,
3123
+ MTRValueKey : @3 ,
3124
+ }
3125
+ },
3126
+ ],
3127
+ }}]];
3128
+
3129
+ [self waitForExpectations: @[ gotAttributeReportExpectation, gotAttributeReportEndExpectation, deviceConfigurationChangedExpectation ] timeout: 60 ];
3130
+ }
3131
+ #endif
3132
+
3023
3133
@end
3024
3134
3025
3135
@interface MTRDeviceEncoderTests : XCTestCase
0 commit comments