Skip to content

Commit 2db400e

Browse files
committed
Addressed review comments
1 parent 754a20c commit 2db400e

File tree

3 files changed

+338
-104
lines changed

3 files changed

+338
-104
lines changed

src/darwin/Framework/CHIP/MTRDevice.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,10 @@ MTR_EXTERN NSString * const MTRDataVersionKey MTR_NEWLY_AVAILABLE;
424424
- (void)deviceCachePrimed:(MTRDevice *)device MTR_NEWLY_AVAILABLE;
425425

426426
/**
427-
* Notifies delegate when the device configuration changes. Device configuration changes include updates in parts list, device type list,
428-
* server list, accepted commands list, attribute list, feature map or cluster revision attributes in the descriptor cluster.
429-
*
430427
* This is called when the MTRDevice object detects a change in the device configuration.
431428
*
429+
* Device configuration is a set of functionality implemented by the device.
430+
*
432431
* The intention is that this is called whenever any of the things that usually don't change about a device might have changed.
433432
*/
434433
- (void)deviceConfigurationChanged:(MTRDevice *)device MTR_NEWLY_AVAILABLE;

src/darwin/Framework/CHIP/MTRDevice.mm

+30-32
Original file line numberDiff line numberDiff line change
@@ -1107,42 +1107,10 @@ - (void)_reportAttributes:(NSArray<NSDictionary<NSString *, id> *> *)attributes
11071107
}
11081108
}
11091109

1110-
// When we receive an attribute report, check if there are any changes in parts list, server list, device type list, accepted commands list,
1111-
// attribute list, cluster revision or feature map attributes of the descriptor cluster. If yes, make a note that the device configuration changed.
1112-
- (void)_noteDeviceConfigurationChanged:(NSArray<NSDictionary<NSString *, id> *> *)attributeReport
1113-
{
1114-
for (NSDictionary<NSString *, id> * attribute in attributeReport) {
1115-
MTRAttributePath * attributePath = attribute[MTRAttributePathKey];
1116-
1117-
if (attributePath.cluster.unsignedLongValue != MTRClusterDescriptorID) {
1118-
return;
1119-
}
1120-
1121-
switch (attributePath.attribute.unsignedLongValue) {
1122-
case MTRClusterDescriptorAttributePartsListID:
1123-
case MTRClusterDescriptorAttributeServerListID:
1124-
case MTRClusterDescriptorAttributeDeviceTypeListID:
1125-
case MTRClusterDescriptorAttributeAcceptedCommandListID:
1126-
case MTRClusterDescriptorAttributeAttributeListID:
1127-
case MTRClusterDescriptorAttributeClusterRevisionID:
1128-
case MTRClusterDescriptorAttributeFeatureMapID: {
1129-
// If changes are detected, note that the device configuration has changed.
1130-
MTRDeviceDataValueDictionary cachedAttributeDataValue = [self _cachedAttributeValueForPath:attributePath];
1131-
if (cachedAttributeDataValue != nil && ![self _attributeDataValue:attribute[MTRDataKey] isEqualToDataValue:cachedAttributeDataValue]) {
1132-
_deviceConfigurationChanged = YES;
1133-
break;
1134-
}
1135-
}
1136-
}
1137-
}
1138-
}
1139-
11401110
- (void)_handleAttributeReport:(NSArray<NSDictionary<NSString *, id> *> *)attributeReport
11411111
{
11421112
std::lock_guard lock(_lock);
11431113

1144-
[self _noteDeviceConfigurationChanged:attributeReport];
1145-
11461114
// _getAttributesToReportWithReportedValues will log attribute paths reported
11471115
[self _reportAttributes:[self _getAttributesToReportWithReportedValues:attributeReport]];
11481116
}
@@ -2421,6 +2389,31 @@ - (void)_noteChangeForClusterPath:(MTRClusterPath *)clusterPath
24212389
[_clustersToPersist addObject:clusterPath];
24222390
}
24232391

2392+
- (BOOL)_isAttributeAffectingDeviceConfigurationChanged:(MTRAttributePath *)attributePath
2393+
{
2394+
// Check for attributes in the descriptor cluster that affect device configuration changed.
2395+
if (attributePath.cluster.unsignedLongValue == MTRClusterIDTypeDescriptorID)
2396+
{
2397+
switch (attributePath.attribute.unsignedLongValue) {
2398+
case MTRAttributeIDTypeClusterDescriptorAttributePartsListID:
2399+
case MTRAttributeIDTypeClusterDescriptorAttributeServerListID:
2400+
case MTRAttributeIDTypeClusterDescriptorAttributeDeviceTypeListID: {
2401+
return YES;
2402+
}
2403+
}
2404+
}
2405+
2406+
// Check for global attributes that affect device configuration changed.
2407+
switch (attributePath.attribute.unsignedLongValue) {
2408+
case MTRAttributeIDTypeGlobalAttributeAcceptedCommandListID:
2409+
case MTRAttributeIDTypeGlobalAttributeAttributeListID:
2410+
case MTRAttributeIDTypeGlobalAttributeClusterRevisionID:
2411+
case MTRAttributeIDTypeGlobalAttributeFeatureMapID:
2412+
return YES;
2413+
}
2414+
return NO;
2415+
}
2416+
24242417
// assume lock is held
24252418
- (NSArray *)_getAttributesToReportWithReportedValues:(NSArray<NSDictionary<NSString *, id> *> *)reportedAttributeValues
24262419
{
@@ -2493,6 +2486,11 @@ - (NSArray *)_getAttributesToReportWithReportedValues:(NSArray<NSDictionary<NSSt
24932486
// when our cached value changes and no expected value exists.
24942487
if (readCacheValueChanged && !expectedValue) {
24952488
shouldReportAttribute = YES;
2489+
2490+
_deviceConfigurationChanged = [self _isAttributeAffectingDeviceConfigurationChanged:attributePath];
2491+
if (_deviceConfigurationChanged) {
2492+
MTR_LOG_INFO("Device configuration changed due to changes in attribute %@", attributePath);
2493+
}
24962494
}
24972495

24982496
// Now that we have grabbed previousValue, update our cache with the attribute value.

0 commit comments

Comments
 (0)