Skip to content

Commit 1687988

Browse files
jtung-applepull[bot]
authored andcommitted
[Darwin] Fix for MTRDevice attribute report omitting errors (#26592)
1 parent 0497419 commit 1687988

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+2-1
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,8 @@ - (NSArray *)_getAttributesToReportWithReportedValues:(NSArray<NSDictionary<NSSt
912912
NSError * attributeError = attributeReponseValue[MTRErrorKey];
913913

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

src/darwin/Framework/CHIPTests/MTRDeviceTests.m

+13
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,19 @@ - (void)test017_TestMTRDeviceBasics
15061506
// nonexistent attribute
15071507
[self waitForExpectations:@[ expectedValueReportedExpectation, expectedValueRemovedExpectation ] timeout:5 enforceOrder:YES];
15081508

1509+
// Test if errors are properly received
1510+
XCTestExpectation * attributeReportErrorExpectation = [self expectationWithDescription:@"Attribute read error"];
1511+
delegate.onAttributeDataReceived = ^(NSArray<NSDictionary<NSString *, id> *> * data) {
1512+
for (NSDictionary<NSString *, id> * attributeReponseValue in data) {
1513+
if (attributeReponseValue[MTRErrorKey]) {
1514+
[attributeReportErrorExpectation fulfill];
1515+
}
1516+
}
1517+
};
1518+
// use the nonexistent attribute and expect read error
1519+
[device readAttributeWithEndpointID:testEndpointID clusterID:testClusterID attributeID:testAttributeID params:nil];
1520+
[self waitForExpectations:@[ attributeReportErrorExpectation ] timeout:10];
1521+
15091522
// reset the onAttributeDataReceived to validate the following resubscribe test
15101523
delegate.onAttributeDataReceived = ^(NSArray<NSDictionary<NSString *, id> *> * data) {
15111524
attributeReportsReceived += data.count;

0 commit comments

Comments
 (0)