@@ -110,9 +110,11 @@ def __post_init__(self):
110
110
'''Only one of either ClusterType and AttributeType OR Path may be provided.'''
111
111
112
112
if (self .ClusterType is not None and self .AttributeType is not None ) and self .Path is not None :
113
- raise ValueError ("Only one of either ClusterType and AttributeType OR Path may be provided." )
113
+ raise ValueError (
114
+ "Only one of either ClusterType and AttributeType OR Path may be provided." )
114
115
if (self .ClusterType is None or self .AttributeType is None ) and self .Path is None :
115
- raise ValueError ("Either ClusterType and AttributeType OR Path must be provided." )
116
+ raise ValueError (
117
+ "Either ClusterType and AttributeType OR Path must be provided." )
116
118
117
119
# if ClusterType and AttributeType were provided we can continue onwards to deriving the label.
118
120
# Otherwise, we'll need to walk the attribute index to find the right type information.
@@ -373,7 +375,8 @@ def handle_cluster_view(endpointId, clusterId, clusterType):
373
375
try :
374
376
decodedData = clusterType .FromDict (
375
377
data = clusterType .descriptor .TagDictToLabelDict ([], self .attributeTLVCache [endpointId ][clusterId ]))
376
- decodedData .SetDataVersion (self .versionList .get (endpointId , {}).get (clusterId ))
378
+ decodedData .SetDataVersion (
379
+ self .versionList .get (endpointId , {}).get (clusterId ))
377
380
return decodedData
378
381
except Exception as ex :
379
382
return ValueDecodeFailure (self .attributeTLVCache [endpointId ][clusterId ], ex )
@@ -404,12 +407,14 @@ def handle_attribute_view(endpointId, clusterId, attributeId, attributeType):
404
407
clusterType = _ClusterIndex [clusterId ]
405
408
406
409
if self .returnClusterObject :
407
- endpointCache [clusterType ] = handle_cluster_view (endpointId , clusterId , clusterType )
410
+ endpointCache [clusterType ] = handle_cluster_view (
411
+ endpointId , clusterId , clusterType )
408
412
else :
409
413
if clusterType not in endpointCache :
410
414
endpointCache [clusterType ] = {}
411
415
clusterCache = endpointCache [clusterType ]
412
- clusterCache [DataVersion ] = self .versionList .get (endpointId , {}).get (clusterId )
416
+ clusterCache [DataVersion ] = self .versionList .get (
417
+ endpointId , {}).get (clusterId )
413
418
414
419
if (clusterId , attributeId ) not in _AttributeIndex :
415
420
#
@@ -419,7 +424,8 @@ def handle_attribute_view(endpointId, clusterId, attributeId, attributeType):
419
424
continue
420
425
421
426
attributeType = _AttributeIndex [(clusterId , attributeId )][0 ]
422
- clusterCache [attributeType ] = handle_attribute_view (endpointId , clusterId , attributeId , attributeType )
427
+ clusterCache [attributeType ] = handle_attribute_view (
428
+ endpointId , clusterId , attributeId , attributeType )
423
429
self ._attributeCacheUpdateNeeded .clear ()
424
430
return self ._attributeCache
425
431
@@ -428,14 +434,18 @@ class SubscriptionTransaction:
428
434
def __init__ (self , transaction : AsyncReadTransaction , subscriptionId , devCtrl ):
429
435
self ._onResubscriptionAttemptedCb : Callable [[SubscriptionTransaction ,
430
436
int , int ], None ] = DefaultResubscriptionAttemptedCallback
431
- self ._onAttributeChangeCb : Callable [[TypedAttributePath , SubscriptionTransaction ], None ] = DefaultAttributeChangeCallback
432
- self ._onEventChangeCb : Callable [[EventReadResult , SubscriptionTransaction ], None ] = DefaultEventChangeCallback
433
- self ._onErrorCb : Callable [[int , SubscriptionTransaction ], None ] = DefaultErrorCallback
437
+ self ._onAttributeChangeCb : Callable [[
438
+ TypedAttributePath , SubscriptionTransaction ], None ] = DefaultAttributeChangeCallback
439
+ self ._onEventChangeCb : Callable [[
440
+ EventReadResult , SubscriptionTransaction ], None ] = DefaultEventChangeCallback
441
+ self ._onErrorCb : Callable [[
442
+ int , SubscriptionTransaction ], None ] = DefaultErrorCallback
434
443
self ._readTransaction = transaction
435
444
self ._subscriptionId = subscriptionId
436
445
self ._devCtrl = devCtrl
437
446
self ._isDone = False
438
- self ._onResubscriptionSucceededCb : Optional [Callable [[SubscriptionTransaction ], None ]] = None
447
+ self ._onResubscriptionSucceededCb : Optional [Callable [[
448
+ SubscriptionTransaction ], None ]] = None
439
449
self ._onResubscriptionSucceededCb_isAsync = False
440
450
self ._onResubscriptionAttemptedCb_isAsync = False
441
451
@@ -460,7 +470,8 @@ def GetEvents(self):
460
470
def OverrideLivenessTimeoutMs (self , timeoutMs : int ):
461
471
handle = chip .native .GetLibraryHandle ()
462
472
builtins .chipStack .Call (
463
- lambda : handle .pychip_ReadClient_OverrideLivenessTimeout (self ._readTransaction ._pReadClient , timeoutMs )
473
+ lambda : handle .pychip_ReadClient_OverrideLivenessTimeout (
474
+ self ._readTransaction ._pReadClient , timeoutMs )
464
475
)
465
476
466
477
async def TriggerResubscribeIfScheduled (self , reason : str ):
@@ -501,7 +512,8 @@ def GetSubscriptionTimeoutMs(self) -> int:
501
512
timeoutMs = ctypes .c_uint32 (0 )
502
513
handle = chip .native .GetLibraryHandle ()
503
514
builtins .chipStack .Call (
504
- lambda : handle .pychip_ReadClient_GetSubscriptionTimeoutMs (self ._readTransaction ._pReadClient , ctypes .pointer (timeoutMs ))
515
+ lambda : handle .pychip_ReadClient_GetSubscriptionTimeoutMs (
516
+ self ._readTransaction ._pReadClient , ctypes .pointer (timeoutMs ))
505
517
)
506
518
return timeoutMs .value
507
519
@@ -567,13 +579,14 @@ def subscriptionId(self) -> int:
567
579
568
580
def Shutdown (self ):
569
581
if (self ._isDone ):
570
- LOGGER .warning ("Subscription 0x%08x was already terminated previously!" , self .subscriptionId )
582
+ LOGGER .warning (
583
+ "Subscription 0x%08x was already terminated previously!" , self .subscriptionId )
571
584
return
572
585
573
586
handle = chip .native .GetLibraryHandle ()
574
587
builtins .chipStack .Call (
575
- lambda : handle .pychip_ReadClient_Abort (
576
- self ._readTransaction ._pReadClient , self . _readTransaction . _pReadCallback ))
588
+ lambda : handle .pychip_ReadClient_ShutdownSubscription (
589
+ self ._readTransaction ._pReadClient ))
577
590
self ._isDone = True
578
591
579
592
def __del__ (self ):
@@ -585,7 +598,8 @@ def __repr__(self):
585
598
586
599
def DefaultResubscriptionAttemptedCallback (transaction : SubscriptionTransaction ,
587
600
terminationError , nextResubscribeIntervalMsec ):
588
- print (f"Previous subscription failed with Error: { terminationError } - re-subscribing in { nextResubscribeIntervalMsec } ms..." )
601
+ print (
602
+ f"Previous subscription failed with Error: { terminationError } - re-subscribing in { nextResubscribeIntervalMsec } ms..." )
589
603
590
604
591
605
def DefaultAttributeChangeCallback (path : TypedAttributePath , transaction : SubscriptionTransaction ):
@@ -648,12 +662,10 @@ def __init__(self, future: Future, eventLoop, devCtrl, returnClusterObject: bool
648
662
self ._cache = AttributeCache (returnClusterObject = returnClusterObject )
649
663
self ._changedPathSet : Set [AttributePath ] = set ()
650
664
self ._pReadClient = None
651
- self ._pReadCallback = None
652
665
self ._resultError : Optional [PyChipError ] = None
653
666
654
- def SetClientObjPointers (self , pReadClient , pReadCallback ):
667
+ def SetClientObjPointers (self , pReadClient ):
655
668
self ._pReadClient = pReadClient
656
- self ._pReadCallback = pReadCallback
657
669
658
670
def GetAllEventValues (self ):
659
671
return self ._events
@@ -729,7 +741,8 @@ def handleEventData(self, header: EventHeader, path: EventPath, data: bytes, sta
729
741
730
742
def handleError (self , chipError : PyChipError ):
731
743
if self ._subscription_handler :
732
- self ._subscription_handler .OnErrorCb (chipError .code , self ._subscription_handler )
744
+ self ._subscription_handler .OnErrorCb (
745
+ chipError .code , self ._subscription_handler )
733
746
self ._resultError = chipError
734
747
735
748
def _handleSubscriptionEstablished (self , subscriptionId ):
@@ -744,7 +757,8 @@ def _handleSubscriptionEstablished(self, subscriptionId):
744
757
self ._event_loop .create_task (
745
758
self ._subscription_handler ._onResubscriptionSucceededCb (self ._subscription_handler ))
746
759
else :
747
- self ._subscription_handler ._onResubscriptionSucceededCb (self ._subscription_handler )
760
+ self ._subscription_handler ._onResubscriptionSucceededCb (
761
+ self ._subscription_handler )
748
762
749
763
def handleSubscriptionEstablished (self , subscriptionId ):
750
764
self ._event_loop .call_soon_threadsafe (
@@ -820,7 +834,8 @@ def __init__(self, future: Future, eventLoop):
820
834
def handleResponse (self , path : AttributePath , status : int ):
821
835
try :
822
836
imStatus = chip .interaction_model .Status (status )
823
- self ._resultData .append (AttributeWriteResult (Path = path , Status = imStatus ))
837
+ self ._resultData .append (
838
+ AttributeWriteResult (Path = path , Status = imStatus ))
824
839
except ValueError as ex :
825
840
LOGGER .exception (ex )
826
841
@@ -835,8 +850,10 @@ def _handleDone(self):
835
850
#
836
851
if self ._resultError is not None :
837
852
if self ._resultError .sdk_part is ErrorSDKPart .IM_GLOBAL_STATUS :
838
- im_status = chip .interaction_model .Status (self ._resultError .sdk_code )
839
- self ._future .set_exception (chip .interaction_model .InteractionModelError (im_status ))
853
+ im_status = chip .interaction_model .Status (
854
+ self ._resultError .sdk_code )
855
+ self ._future .set_exception (
856
+ chip .interaction_model .InteractionModelError (im_status ))
840
857
else :
841
858
self ._future .set_exception (self ._resultError .to_exception ())
842
859
else :
@@ -856,7 +873,8 @@ def handleDone(self):
856
873
_OnReadAttributeDataCallbackFunct = CFUNCTYPE (
857
874
None , py_object , c_uint32 , c_uint16 , c_uint32 , c_uint32 , c_uint8 , c_void_p , c_size_t )
858
875
_OnSubscriptionEstablishedCallbackFunct = CFUNCTYPE (None , py_object , c_uint32 )
859
- _OnResubscriptionAttemptedCallbackFunct = CFUNCTYPE (None , py_object , PyChipError , c_uint32 )
876
+ _OnResubscriptionAttemptedCallbackFunct = CFUNCTYPE (
877
+ None , py_object , PyChipError , c_uint32 )
860
878
_OnReadEventDataCallbackFunct = CFUNCTYPE (
861
879
None , py_object , c_uint16 , c_uint32 , c_uint32 , c_uint64 , c_uint8 , c_uint64 , c_uint8 , c_void_p , c_size_t , c_uint8 )
862
880
_OnReadErrorCallbackFunct = CFUNCTYPE (
@@ -897,7 +915,8 @@ def _OnSubscriptionEstablishedCallback(closure, subscriptionId):
897
915
898
916
@_OnResubscriptionAttemptedCallbackFunct
899
917
def _OnResubscriptionAttemptedCallback (closure , terminationCause : PyChipError , nextResubscribeIntervalMsec : int ):
900
- closure .handleResubscriptionAttempted (terminationCause , nextResubscribeIntervalMsec )
918
+ closure .handleResubscriptionAttempted (
919
+ terminationCause , nextResubscribeIntervalMsec )
901
920
902
921
903
922
@_OnReadErrorCallbackFunct
@@ -954,25 +973,34 @@ def WriteAttributes(future: Future, eventLoop, device,
954
973
pyWriteAttributes = pyWriteAttributesArrayType ()
955
974
for idx , attr in enumerate (attributes ):
956
975
if attr .Attribute .must_use_timed_write and timedRequestTimeoutMs is None or timedRequestTimeoutMs == 0 :
957
- raise chip .interaction_model .InteractionModelError (chip .interaction_model .Status .NeedsTimedInteraction )
976
+ raise chip .interaction_model .InteractionModelError (
977
+ chip .interaction_model .Status .NeedsTimedInteraction )
958
978
959
979
tlv = attr .Attribute .ToTLV (None , attr .Data )
960
980
961
- pyWriteAttributes [idx ].attributePath .endpointId = c_uint16 (attr .EndpointId )
962
- pyWriteAttributes [idx ].attributePath .clusterId = c_uint32 (attr .Attribute .cluster_id )
963
- pyWriteAttributes [idx ].attributePath .attributeId = c_uint32 (attr .Attribute .attribute_id )
964
- pyWriteAttributes [idx ].attributePath .dataVersion = c_uint32 (attr .DataVersion )
965
- pyWriteAttributes [idx ].attributePath .hasDataVersion = c_uint8 (attr .HasDataVersion )
966
- pyWriteAttributes [idx ].tlvData = cast (ctypes .c_char_p (bytes (tlv )), c_void_p )
981
+ pyWriteAttributes [idx ].attributePath .endpointId = c_uint16 (
982
+ attr .EndpointId )
983
+ pyWriteAttributes [idx ].attributePath .clusterId = c_uint32 (
984
+ attr .Attribute .cluster_id )
985
+ pyWriteAttributes [idx ].attributePath .attributeId = c_uint32 (
986
+ attr .Attribute .attribute_id )
987
+ pyWriteAttributes [idx ].attributePath .dataVersion = c_uint32 (
988
+ attr .DataVersion )
989
+ pyWriteAttributes [idx ].attributePath .hasDataVersion = c_uint8 (
990
+ attr .HasDataVersion )
991
+ pyWriteAttributes [idx ].tlvData = cast (
992
+ ctypes .c_char_p (bytes (tlv )), c_void_p )
967
993
pyWriteAttributes [idx ].tlvLength = c_size_t (len (tlv ))
968
994
969
995
transaction = AsyncWriteTransaction (future , eventLoop )
970
996
ctypes .pythonapi .Py_IncRef (ctypes .py_object (transaction ))
971
997
res = builtins .chipStack .Call (
972
998
lambda : handle .pychip_WriteClient_WriteAttributes (
973
999
ctypes .py_object (transaction ), device ,
974
- ctypes .c_size_t (0 if timedRequestTimeoutMs is None else timedRequestTimeoutMs ),
975
- ctypes .c_size_t (0 if interactionTimeoutMs is None else interactionTimeoutMs ),
1000
+ ctypes .c_size_t (
1001
+ 0 if timedRequestTimeoutMs is None else timedRequestTimeoutMs ),
1002
+ ctypes .c_size_t (
1003
+ 0 if interactionTimeoutMs is None else interactionTimeoutMs ),
976
1004
ctypes .c_size_t (0 if busyWaitMs is None else busyWaitMs ),
977
1005
pyWriteAttributes , ctypes .c_size_t (numberOfAttributes ))
978
1006
)
@@ -991,12 +1019,18 @@ def WriteGroupAttributes(groupId: int, devCtrl: c_void_p, attributes: List[Attri
991
1019
992
1020
tlv = attr .Attribute .ToTLV (None , attr .Data )
993
1021
994
- pyWriteAttributes [idx ].attributePath .endpointId = c_uint16 (attr .EndpointId )
995
- pyWriteAttributes [idx ].attributePath .clusterId = c_uint32 (attr .Attribute .cluster_id )
996
- pyWriteAttributes [idx ].attributePath .attributeId = c_uint32 (attr .Attribute .attribute_id )
997
- pyWriteAttributes [idx ].attributePath .dataVersion = c_uint32 (attr .DataVersion )
998
- pyWriteAttributes [idx ].attributePath .hasDataVersion = c_uint8 (attr .HasDataVersion )
999
- pyWriteAttributes [idx ].tlvData = cast (ctypes .c_char_p (bytes (tlv )), c_void_p )
1022
+ pyWriteAttributes [idx ].attributePath .endpointId = c_uint16 (
1023
+ attr .EndpointId )
1024
+ pyWriteAttributes [idx ].attributePath .clusterId = c_uint32 (
1025
+ attr .Attribute .cluster_id )
1026
+ pyWriteAttributes [idx ].attributePath .attributeId = c_uint32 (
1027
+ attr .Attribute .attribute_id )
1028
+ pyWriteAttributes [idx ].attributePath .dataVersion = c_uint32 (
1029
+ attr .DataVersion )
1030
+ pyWriteAttributes [idx ].attributePath .hasDataVersion = c_uint8 (
1031
+ attr .HasDataVersion )
1032
+ pyWriteAttributes [idx ].tlvData = cast (
1033
+ ctypes .c_char_p (bytes (tlv )), c_void_p )
1000
1034
pyWriteAttributes [idx ].tlvLength = c_size_t (len (tlv ))
1001
1035
1002
1036
return builtins .chipStack .Call (
@@ -1071,7 +1105,8 @@ def Read(transaction: AsyncReadTransaction, device,
1071
1105
"DataVersionFilter must provide DataVersion." )
1072
1106
filter = chip .interaction_model .DataVersionFilterIBstruct .build (
1073
1107
filter )
1074
- dataVersionFiltersForCffi [idx ] = cast (ctypes .c_char_p (filter ), c_void_p )
1108
+ dataVersionFiltersForCffi [idx ] = cast (
1109
+ ctypes .c_char_p (filter ), c_void_p )
1075
1110
1076
1111
eventPathsForCffi = None
1077
1112
if events is not None :
@@ -1095,7 +1130,6 @@ def Read(transaction: AsyncReadTransaction, device,
1095
1130
eventPathsForCffi [idx ] = cast (ctypes .c_char_p (path ), c_void_p )
1096
1131
1097
1132
readClientObj = ctypes .POINTER (c_void_p )()
1098
- readCallbackObj = ctypes .POINTER (c_void_p )()
1099
1133
1100
1134
ctypes .pythonapi .Py_IncRef (ctypes .py_object (transaction ))
1101
1135
params = _ReadParams .parse (b'\x00 ' * _ReadParams .sizeof ())
@@ -1109,13 +1143,13 @@ def Read(transaction: AsyncReadTransaction, device,
1109
1143
params = _ReadParams .build (params )
1110
1144
eventNumberFilterPtr = ctypes .POINTER (ctypes .c_ulonglong )()
1111
1145
if eventNumberFilter is not None :
1112
- eventNumberFilterPtr = ctypes .POINTER (ctypes .c_ulonglong )(ctypes .c_ulonglong (eventNumberFilter ))
1146
+ eventNumberFilterPtr = ctypes .POINTER (ctypes .c_ulonglong )(
1147
+ ctypes .c_ulonglong (eventNumberFilter ))
1113
1148
1114
1149
res = builtins .chipStack .Call (
1115
1150
lambda : handle .pychip_ReadClient_Read (
1116
1151
ctypes .py_object (transaction ),
1117
1152
ctypes .byref (readClientObj ),
1118
- ctypes .byref (readCallbackObj ),
1119
1153
device ,
1120
1154
ctypes .c_char_p (params ),
1121
1155
attributePathsForCffi ,
@@ -1127,7 +1161,7 @@ def Read(transaction: AsyncReadTransaction, device,
1127
1161
ctypes .c_size_t (0 if events is None else len (events )),
1128
1162
eventNumberFilterPtr ))
1129
1163
1130
- transaction .SetClientObjPointers (readClientObj , readCallbackObj )
1164
+ transaction .SetClientObjPointers (readClientObj )
1131
1165
1132
1166
if not res .is_success :
1133
1167
ctypes .pythonapi .Py_DecRef (ctypes .py_object (transaction ))
0 commit comments