Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report an attribute if a read will get a changed value and no expected value exists #33014

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2342,25 +2342,26 @@ - (NSArray *)_getAttributesToReportWithReportedValues:(NSArray<NSDictionary<NSSt
[attributesToPersist addObject:attributeResponseValueToPersist];
#endif
}

// if expected values exists, purge and update read cache
NSArray * expectedValue = _expectedValueCache[attributePath];
if (expectedValue) {
previousValue = expectedValue[MTRDeviceExpectedValueFieldValueIndex];
_readCache[attributePath] = attributeDataValue;
shouldReportAttribute = NO;
} else if (readCacheValueChanged) {
// otherwise compare and update read cache

// Report the attribute if a read would get a changed value. This happens
// when our cached value changes and no expected value exists.
if (readCacheValueChanged && !expectedValue) {
previousValue = _readCache[attributePath];
_readCache[attributePath] = attributeDataValue;
shouldReportAttribute = YES;
}

// Now that we have grabbed previousValue, update the readCache with the attribute value.
_readCache[attributePath] = attributeDataValue;

if (!shouldReportAttribute) {
// If an expected value exists, the attribute will not be reported at this time.
// When the expected value interval expires, the correct value will be reported,
// if needed.
if (expectedValue) {
MTR_LOG_INFO("%@ report %@ value filtered - same as expected values", self, attributePath);
MTR_LOG_INFO("%@ report %@ value filtered - expected value still present", self, attributePath);
} else {
MTR_LOG_INFO("%@ report %@ value filtered - same values as cache", self, attributePath);
MTR_LOG_INFO("%@ report %@ value filtered - same as read cache", self, attributePath);
}
}

Expand Down
Loading