Skip to content

Commit

Permalink
[Darwin] Fix MTRDevice getAllAttributesReport return value (#35471)
Browse files Browse the repository at this point in the history
* [Darwin] Fix MTRDevice getAllAttributesReport return value

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
jtung-apple and restyled-commits authored Sep 7, 2024
1 parent 3cb4b51 commit f633e43
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 @@ -3511,8 +3511,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 f633e43

Please sign in to comment.