@@ -383,7 +383,7 @@ def UpdateTLV(self, path: AttributePath, dataVersion: int, data: Union[bytes, V
383
383
384
384
clusterCache [path .AttributeId ] = data
385
385
386
- def UpdateCachedData (self ):
386
+ def UpdateCachedData (self , changedPathSet : set [ AttributePath ] ):
387
387
''' This converts the raw TLV data into a cluster object format.
388
388
389
389
Two formats are available:
@@ -401,68 +401,72 @@ def UpdateCachedData(self):
401
401
tlvCache = self .attributeTLVCache
402
402
attributeCache = self .attributeCache
403
403
404
- for endpoint in tlvCache :
405
- if (endpoint not in attributeCache ):
406
- attributeCache [endpoint ] = {}
404
+ for attributePath in changedPathSet :
405
+ endpointId = attributePath .EndpointId
407
406
408
- endpointCache = attributeCache [endpoint ]
407
+ if endpointId not in attributeCache :
408
+ attributeCache [endpointId ] = {}
409
409
410
- for cluster in tlvCache [endpoint ]:
411
- if cluster not in _ClusterIndex :
410
+ endpointCache = attributeCache [endpointId ]
411
+
412
+ clusterId = attributePath .ClusterId
413
+
414
+ if clusterId not in _ClusterIndex :
415
+ #
416
+ # #22599 tracks dealing with unknown clusters more
417
+ # gracefully so that clients can still access this data.
418
+ #
419
+ continue
420
+
421
+ clusterType = _ClusterIndex [clusterId ]
422
+
423
+ if clusterType not in endpointCache :
424
+ endpointCache [clusterType ] = {}
425
+
426
+ clusterCache = endpointCache [clusterType ]
427
+ clusterDataVersion = self .versionList .get (
428
+ endpointId , {}).get (clusterId , None )
429
+
430
+ if self .returnClusterObject :
431
+ try :
432
+ # Since the TLV data is already organized by attribute tags, we can trivially convert to a cluster object representation.
433
+ endpointCache [clusterType ] = clusterType .FromDict (
434
+ data = clusterType .descriptor .TagDictToLabelDict ([], tlvCache [endpointId ][clusterId ]))
435
+ endpointCache [clusterType ].SetDataVersion (
436
+ clusterDataVersion )
437
+ except Exception as ex :
438
+ decodedValue = ValueDecodeFailure (
439
+ tlvCache [endpointId ][clusterId ], ex )
440
+ endpointCache [clusterType ] = decodedValue
441
+ else :
442
+ clusterCache [DataVersion ] = clusterDataVersion
443
+
444
+ attributeId = attributePath .AttributeId
445
+
446
+ value = tlvCache [endpointId ][clusterId ][attributeId ]
447
+
448
+ if (clusterId , attributeId ) not in _AttributeIndex :
412
449
#
413
450
# #22599 tracks dealing with unknown clusters more
414
451
# gracefully so that clients can still access this data.
415
452
#
416
453
continue
417
454
418
- clusterType = _ClusterIndex [cluster ]
419
-
420
- if (clusterType not in endpointCache ):
421
- endpointCache [clusterType ] = {}
455
+ attributeType = _AttributeIndex [(clusterId , attributeId )][0 ]
422
456
423
- clusterCache = endpointCache [clusterType ]
424
- clusterDataVersion = self .versionList .get (
425
- endpoint , {}).get (cluster , None )
457
+ if attributeType not in clusterCache :
458
+ clusterCache [attributeType ] = {}
426
459
427
- if (self .returnClusterObject ):
460
+ if isinstance (value , ValueDecodeFailure ):
461
+ clusterCache [attributeType ] = value
462
+ else :
428
463
try :
429
- # Since the TLV data is already organized by attribute tags, we can trivially convert to a cluster object representation.
430
- endpointCache [clusterType ] = clusterType .FromDict (
431
- data = clusterType .descriptor .TagDictToLabelDict ([], tlvCache [endpoint ][cluster ]))
432
- endpointCache [clusterType ].SetDataVersion (
433
- clusterDataVersion )
464
+ decodedValue = attributeType .FromTagDictOrRawValue (
465
+ tlvCache [endpointId ][clusterId ][attributeId ])
434
466
except Exception as ex :
435
- decodedValue = ValueDecodeFailure (
436
- tlvCache [endpoint ][cluster ], ex )
437
- endpointCache [clusterType ] = decodedValue
438
- else :
439
- clusterCache [DataVersion ] = clusterDataVersion
440
- for attribute in tlvCache [endpoint ][cluster ]:
441
- value = tlvCache [endpoint ][cluster ][attribute ]
442
-
443
- if (cluster , attribute ) not in _AttributeIndex :
444
- #
445
- # #22599 tracks dealing with unknown clusters more
446
- # gracefully so that clients can still access this data.
447
- #
448
- continue
449
-
450
- attributeType = _AttributeIndex [(
451
- cluster , attribute )][0 ]
452
-
453
- if (attributeType not in clusterCache ):
454
- clusterCache [attributeType ] = {}
455
-
456
- if (type (value ) is ValueDecodeFailure ):
457
- clusterCache [attributeType ] = value
458
- else :
459
- try :
460
- decodedValue = attributeType .FromTagDictOrRawValue (
461
- tlvCache [endpoint ][cluster ][attribute ])
462
- except Exception as ex :
463
- decodedValue = ValueDecodeFailure (value , ex )
467
+ decodedValue = ValueDecodeFailure (value , ex )
464
468
465
- clusterCache [attributeType ] = decodedValue
469
+ clusterCache [attributeType ] = decodedValue
466
470
467
471
468
472
class SubscriptionTransaction :
@@ -766,7 +770,7 @@ def _handleReportBegin(self):
766
770
pass
767
771
768
772
def _handleReportEnd (self ):
769
- self ._cache .UpdateCachedData ()
773
+ self ._cache .UpdateCachedData (self . _changedPathSet )
770
774
771
775
if (self ._subscription_handler is not None ):
772
776
for change in self ._changedPathSet :
0 commit comments