Skip to content

Commit

Permalink
Remove expected value check from the _getAttributesToReportWithReport…
Browse files Browse the repository at this point in the history
…edValues

- Report the attribute only when the value has changed from the read cache.

- Fix logging for use cases where we didn't report since there was an expected value
or the attribute value didn't change from the read cache value.
  • Loading branch information
nivi-apple committed Apr 16, 2024
1 parent 90732b2 commit d5e2a4f
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2343,24 +2343,25 @@ - (NSArray *)_getAttributesToReportWithReportedValues:(NSArray<NSDictionary<NSSt
#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 the attribute value is different from the read cache value.
if (readCacheValueChanged) {
previousValue = _readCache[attributePath];
_readCache[attributePath] = attributeDataValue;
shouldReportAttribute = YES;
}

// Update the readCache with the attribute value.
_readCache[attributePath] = attributeDataValue;

if (!shouldReportAttribute) {

NSArray * expectedValue = _expectedValueCache[attributePath];
// If an expected value exists, do not report the attribute during this time.
// When the expected value interval expires, the correct value will be reported.
if (expectedValue) {
MTR_LOG_INFO("%@ report %@ value filtered - same as expected values", self, attributePath);
} else {
MTR_LOG_INFO("%@ report %@ value filtered - same values as cache", self, attributePath);
MTR_LOG_INFO("%@ report %@ value filtered - new expected value present. Do not report old value", self, attributePath);
} else
{
MTR_LOG_INFO("%@ report %@ value filtered - same as read cache", self, attributePath);
}
}

Expand Down

0 comments on commit d5e2a4f

Please sign in to comment.