@@ -2770,109 +2770,93 @@ - (void)_pruneOrphanedEndpointsAndClusters:(MTRAttributePath *)attributePath
2770
2770
{
2771
2771
os_unfair_lock_assert_owner(&self->_lock);
2772
2772
2773
- if (_persistedClusters == nil || _persistedClusterData == nil || !previousValue.count)
2774
- {
2773
+ if (_persistedClusters == nil || _persistedClusterData == nil || !previousValue.count) {
2775
2774
return;
2776
2775
}
2777
2776
// Check if parts list changed or server list changed for the descriptor cluster or the attribute list changed for a cluster.
2778
2777
// If yes, we might need to prune any deleted endpoints, clusters or attributes from the storage and persisted cluster data.
2779
2778
if (attributePath.cluster.unsignedLongValue == MTRClusterIDTypeDescriptorID) {
2780
2779
switch (attributePath.attribute.unsignedLongValue) {
2781
2780
2782
- // If the parts list changed and one or more endpoints were removed, remove all the clusters in _persistedClusters and _persistedClusterData for all those endpoints.
2783
- // Also remove it from the data store.
2784
- case MTRAttributeIDTypeClusterDescriptorAttributePartsListID:
2785
- {
2786
- NSMutableSet * toBeRemovedEndpoints = [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:previousValue]];
2787
- NSSet * endpointsOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2788
- [toBeRemovedEndpoints minusSet:endpointsOnDevice];
2789
-
2790
- for (NSNumber * endpoint in toBeRemovedEndpoints)
2791
- {
2792
- NSMutableSet<MTRClusterPath *> * clusterPathsToRemove = [[NSMutableSet alloc]init];
2793
- for (MTRClusterPath * path in _persistedClusters)
2794
- {
2795
- if ([path.endpoint isEqualToNumber:endpoint])
2796
- {
2797
- [clusterPathsToRemove addObject:path];
2798
- [_persistedClusterData removeObjectForKey:path];
2799
- [self.deviceController.controllerDataStore clearStoredClusterDataForNodeIDWithEndpointID:self.nodeID endpointID:endpoint];
2800
- }
2781
+ // If the parts list changed and one or more endpoints were removed, remove all the clusters in _persistedClusters and _persistedClusterData for all those endpoints.
2782
+ // Also remove it from the data store.
2783
+ case MTRAttributeIDTypeClusterDescriptorAttributePartsListID: {
2784
+ NSMutableSet * toBeRemovedEndpoints = [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:previousValue]];
2785
+ NSSet * endpointsOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2786
+ [toBeRemovedEndpoints minusSet:endpointsOnDevice];
2787
+
2788
+ for (NSNumber * endpoint in toBeRemovedEndpoints) {
2789
+ NSMutableSet<MTRClusterPath *> * clusterPathsToRemove = [[NSMutableSet alloc] init];
2790
+ for (MTRClusterPath * path in _persistedClusters) {
2791
+ if ([path.endpoint isEqualToNumber:endpoint]) {
2792
+ [clusterPathsToRemove addObject:path];
2793
+ [_persistedClusterData removeObjectForKey:path];
2794
+ [self.deviceController.controllerDataStore clearStoredClusterDataForNodeIDWithEndpointID:self.nodeID endpointID:endpoint];
2801
2795
}
2802
- [_persistedClusters minusSet:clusterPathsToRemove];
2803
2796
}
2804
- break ;
2797
+ [_persistedClusters minusSet:clusterPathsToRemove] ;
2805
2798
}
2799
+ break;
2800
+ }
2806
2801
2807
- // If the server list changed and clusters were removed, remove the clusters from the _persistedClusters and _persistedClusterData for that endpoint
2808
- // Also remove it from the data store.
2809
- case MTRAttributeIDTypeClusterDescriptorAttributeServerListID:
2810
- {
2811
- NSMutableSet * toBeRemovedClusters= [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:previousValue]];
2812
- NSSet * clustersOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2813
- [toBeRemovedClusters minusSet:clustersOnDevice];
2814
-
2815
- NSMutableSet<MTRClusterPath *> * clusterPathsToRemove = [[NSMutableSet alloc]init];
2816
- for (NSNumber * cluster in toBeRemovedClusters)
2817
- {
2818
- for (MTRClusterPath * path in _persistedClusters)
2819
- {
2820
- if ([path.endpoint isEqualToNumber:attributePath.endpoint] && [path.cluster isEqualToNumber:cluster])
2821
- {
2822
- [clusterPathsToRemove addObject:path];
2823
- [_persistedClusterData removeObjectForKey:path];
2824
-
2825
- [self.deviceController.controllerDataStore clearStoredClusterDataForNodeIDWithClusterID:self.nodeID endpointID:path.endpoint clusterID:path.cluster];
2826
- }
2802
+ // If the server list changed and clusters were removed, remove the clusters from the _persistedClusters and _persistedClusterData for that endpoint
2803
+ // Also remove it from the data store.
2804
+ case MTRAttributeIDTypeClusterDescriptorAttributeServerListID: {
2805
+ NSMutableSet * toBeRemovedClusters = [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:previousValue]];
2806
+ NSSet * clustersOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2807
+ [toBeRemovedClusters minusSet:clustersOnDevice];
2808
+
2809
+ NSMutableSet<MTRClusterPath *> * clusterPathsToRemove = [[NSMutableSet alloc] init];
2810
+ for (NSNumber * cluster in toBeRemovedClusters) {
2811
+ for (MTRClusterPath * path in _persistedClusters) {
2812
+ if ([path.endpoint isEqualToNumber:attributePath.endpoint] && [path.cluster isEqualToNumber:cluster]) {
2813
+ [clusterPathsToRemove addObject:path];
2814
+ [_persistedClusterData removeObjectForKey:path];
2815
+
2816
+ [self.deviceController.controllerDataStore clearStoredClusterDataForNodeIDWithClusterID:self.nodeID endpointID:path.endpoint clusterID:path.cluster];
2827
2817
}
2828
2818
}
2829
- [_persistedClusters minusSet:clusterPathsToRemove];
2830
- break;
2831
2819
}
2820
+ [_persistedClusters minusSet:clusterPathsToRemove];
2821
+ break;
2822
+ }
2832
2823
}
2833
2824
}
2834
2825
2835
2826
switch (attributePath.attribute.unsignedLongValue) {
2836
- // If the attribute list changed and attributes were removed, remove the attributes from the _persistedClusterData for that cluster and endpoint.
2837
- // Also remove it from the data store cluster data.
2838
- case MTRAttributeIDTypeGlobalAttributeAttributeListID:
2839
- {
2840
- NSMutableSet * toBeRemovedAttributes= [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:[self _cachedAttributeValueForPath:attributePath]]];
2841
- NSSet * attributesOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2842
-
2843
- [toBeRemovedAttributes minusSet:attributesOnDevice];
2844
- for (NSNumber * attribute in toBeRemovedAttributes)
2845
- {
2846
- for (MTRClusterPath * path in _persistedClusters)
2847
- {
2848
- if ([path.endpoint isEqualToNumber:attributePath.endpoint] && [path.cluster isEqualToNumber:attributePath.cluster])
2849
- {
2850
- MTRDeviceClusterData * clusterData = [self _clusterDataForPath:path];
2851
- if (clusterData == nil)
2852
- {
2853
- return;
2854
- }
2855
- [clusterData _removeValueForAttribute:attribute];
2856
- [self->_persistedClusterData setObject:clusterData forKey:path];
2857
-
2858
- NSDictionary<MTRClusterPath *, MTRDeviceClusterData *> * dataStoreClusterData = [self.deviceController.controllerDataStore getStoredClusterDataForNodeID:self.nodeID];
2859
- NSMutableDictionary<MTRClusterPath *, MTRDeviceClusterData *> * dataStoreClusterDataCopy = [dataStoreClusterData mutableCopy];
2860
- for (MTRClusterPath * dataStorePath in dataStoreClusterData)
2861
- {
2862
- if ([dataStorePath isEqualTo:path])
2863
- {
2864
- [dataStoreClusterDataCopy removeObjectForKey:path];
2865
- [dataStoreClusterDataCopy setObject:clusterData forKey:path];
2866
- [self.deviceController.controllerDataStore storeClusterData:dataStoreClusterDataCopy forNodeID:self.nodeID];
2867
- dataStoreClusterData = [NSMutableDictionary dictionaryWithDictionary:[self.deviceController.controllerDataStore getStoredClusterDataForNodeID:self.nodeID]];
2868
- }
2827
+ // If the attribute list changed and attributes were removed, remove the attributes from the _persistedClusterData for that cluster and endpoint.
2828
+ // Also remove it from the data store cluster data.
2829
+ case MTRAttributeIDTypeGlobalAttributeAttributeListID: {
2830
+ NSMutableSet * toBeRemovedAttributes = [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:[self _cachedAttributeValueForPath:attributePath]]];
2831
+ NSSet * attributesOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2832
+
2833
+ [toBeRemovedAttributes minusSet:attributesOnDevice];
2834
+ for (NSNumber * attribute in toBeRemovedAttributes) {
2835
+ for (MTRClusterPath * path in _persistedClusters) {
2836
+ if ([path.endpoint isEqualToNumber:attributePath.endpoint] && [path.cluster isEqualToNumber:attributePath.cluster]) {
2837
+ MTRDeviceClusterData * clusterData = [self _clusterDataForPath:path];
2838
+ if (clusterData == nil) {
2839
+ return;
2840
+ }
2841
+ [clusterData _removeValueForAttribute:attribute];
2842
+ [self->_persistedClusterData setObject:clusterData forKey:path];
2843
+
2844
+ NSDictionary<MTRClusterPath *, MTRDeviceClusterData *> * dataStoreClusterData = [self.deviceController.controllerDataStore getStoredClusterDataForNodeID:self.nodeID];
2845
+ NSMutableDictionary<MTRClusterPath *, MTRDeviceClusterData *> * dataStoreClusterDataCopy = [dataStoreClusterData mutableCopy];
2846
+ for (MTRClusterPath * dataStorePath in dataStoreClusterData) {
2847
+ if ([dataStorePath isEqualTo:path]) {
2848
+ [dataStoreClusterDataCopy removeObjectForKey:path];
2849
+ [dataStoreClusterDataCopy setObject:clusterData forKey:path];
2850
+ [self.deviceController.controllerDataStore storeClusterData:dataStoreClusterDataCopy forNodeID:self.nodeID];
2851
+ dataStoreClusterData = [NSMutableDictionary dictionaryWithDictionary:[self.deviceController.controllerDataStore getStoredClusterDataForNodeID:self.nodeID]];
2869
2852
}
2870
- [self _removeCachedAttributeValue:path forPath:attributePath];
2871
2853
}
2854
+ [self _removeCachedAttributeValue:path forPath:attributePath];
2872
2855
}
2873
2856
}
2874
- break;
2875
2857
}
2858
+ break;
2859
+ }
2876
2860
}
2877
2861
}
2878
2862
@@ -2929,8 +2913,7 @@ - (NSArray *)_getAttributesToReportWithReportedValues:(NSArray<NSDictionary<NSSt
2929
2913
[self _noteDataVersion:dataVersion forClusterPath:clusterPath];
2930
2914
}
2931
2915
2932
- if ([self _needsPruningOfEndpointsAndClusters:attributePath])
2933
- {
2916
+ if ([self _needsPruningOfEndpointsAndClusters:attributePath]) {
2934
2917
previousValue = [self _dataValueWithoutDataVersion:previousValue];
2935
2918
[self _pruneOrphanedEndpointsAndClusters:attributePath previousValue:previousValue attributeDataValue:attributeDataValue];
2936
2919
}
@@ -3099,8 +3082,7 @@ - (void)_storePersistedDeviceData
3099
3082
- (void)_removePersistedClusterDataForPath:(MTRClusterPath *)path
3100
3083
{
3101
3084
os_unfair_lock_assert_owner(&self->_lock);
3102
- if (_persistedClusters == nil || _persistedClusterData == nil)
3103
- {
3085
+ if (_persistedClusters == nil || _persistedClusterData == nil) {
3104
3086
return;
3105
3087
}
3106
3088
@@ -3119,8 +3101,7 @@ - (MTRDeviceClusterData *)_getPersistedClusterDataForPath:(MTRClusterPath *)path
3119
3101
{
3120
3102
std::lock_guard lock(_lock);
3121
3103
3122
- if ([_persistedClusters containsObject:path])
3123
- {
3104
+ if ([_persistedClusters containsObject:path]) {
3124
3105
return [_persistedClusterData objectForKey:path];
3125
3106
}
3126
3107
return nil;
@@ -3130,8 +3111,7 @@ - (BOOL)_persistedClusterContains:(MTRClusterPath *)path
3130
3111
{
3131
3112
std::lock_guard lock(_lock);
3132
3113
3133
- if ([_persistedClusters containsObject:path])
3134
- {
3114
+ if ([_persistedClusters containsObject:path]) {
3135
3115
return YES;
3136
3116
}
3137
3117
return NO;
0 commit comments