Skip to content

Commit

Permalink
[Darwin] Fix MTRDevice getAllAttributesReport return value
Browse files Browse the repository at this point in the history
  • Loading branch information
jtung-apple committed Sep 7, 2024
1 parent b3d527e commit d8e1358
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3497,8 +3497,12 @@ - (NSArray *)_getAttributesToReportWithReportedValues:(NSArray<NSDictionary<NSSt
clusterID:clusterPath.cluster
attributeID:attributeID];

// Using _lockedAttributeValueDictionaryForAttributePath because it takes into consideration expected values too
[attributeReport addObject:[self _lockedAttributeValueDictionaryForAttributePath:attributePath]];
// Construct response-value dictionary with the data-value dictionary returned by
// _lockedAttributeValueDictionaryForAttributePath, to takes into consideration expected values as well.
[attributeReport addObject:@{
MTRAttributePathKey: attributePath,
MTRDataKey: [self _lockedAttributeValueDictionaryForAttributePath:attributePath]
}];
}
}

Expand Down
23 changes: 20 additions & 3 deletions src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -4323,11 +4323,28 @@ - (void)test039_GetAllAttributesReport

[self waitForExpectations:@[ gotReportEnd ] timeout:60];

XCTAssertEqual(attributesReceived, 36);

NSArray * allAttributesReport = [device getAllAttributesReport];

XCTAssertEqual(allAttributesReport.count, 36);
XCTAssertEqual(allAttributesReport.count, attributeReport.count);

for (NSDictionary<NSString *, id> *newResponseValueDict in allAttributesReport) {
MTRAttributePath *newPath = newResponseValueDict[MTRAttributePathKey];
NSDictionary<NSString *, id> *newDataValueDict = newResponseValueDict[MTRDataKey];
NSNumber *newValue = newDataValueDict[MTRValueKey];
XCTAssertNotNil(newValue);

for (NSDictionary<NSString *, id> *originalResponseValueDict in attributeReport) {
MTRAttributePath *originalPath = originalResponseValueDict[MTRAttributePathKey];
// Find same attribute path and compare value
if ([newPath isEqual:originalPath]) {
NSDictionary<NSString *, id> *originalDataValueDict = originalResponseValueDict[MTRDataKey];
NSNumber *originalValue = originalDataValueDict[MTRValueKey];
XCTAssertNotNil(originalValue);
XCTAssertEqualObjects(newValue, originalValue);
continue;
}
}
}
}

@end
Expand Down

0 comments on commit d8e1358

Please sign in to comment.