Skip to content

Commit

Permalink
[Darwin] Fix for MTRDevice attribute report omitting errors (#26592)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtung-apple authored and pull[bot] committed Jul 19, 2023
1 parent 9ddee98 commit 1349405
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,8 @@ - (NSArray *)_getAttributesToReportWithReportedValues:(NSArray<NSDictionary<NSSt
NSError * attributeError = attributeReponseValue[MTRErrorKey];

// sanity check either data value or error must exist
if (!attributeDataValue && attributeError) {
if (!attributeDataValue && !attributeError) {
MTR_LOG_INFO("%@ report %@ no data value or error: %@", self, attributePath, attributeReponseValue);
continue;
}

Expand Down
13 changes: 13 additions & 0 deletions src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,19 @@ - (void)test017_TestMTRDeviceBasics
// nonexistent attribute
[self waitForExpectations:@[ expectedValueReportedExpectation, expectedValueRemovedExpectation ] timeout:5 enforceOrder:YES];

// Test if errors are properly received
XCTestExpectation * attributeReportErrorExpectation = [self expectationWithDescription:@"Attribute read error"];
delegate.onAttributeDataReceived = ^(NSArray<NSDictionary<NSString *, id> *> * data) {
for (NSDictionary<NSString *, id> * attributeReponseValue in data) {
if (attributeReponseValue[MTRErrorKey]) {
[attributeReportErrorExpectation fulfill];
}
}
};
// use the nonexistent attribute and expect read error
[device readAttributeWithEndpointID:testEndpointID clusterID:testClusterID attributeID:testAttributeID params:nil];
[self waitForExpectations:@[ attributeReportErrorExpectation ] timeout:10];

// reset the onAttributeDataReceived to validate the following resubscribe test
delegate.onAttributeDataReceived = ^(NSArray<NSDictionary<NSString *, id> *> * data) {
attributeReportsReceived += data.count;
Expand Down

0 comments on commit 1349405

Please sign in to comment.