@@ -579,6 +579,15 @@ def SetErrorCallback(self, callback: Callable[[int, SubscriptionTransaction], No
579
579
if callback is not None :
580
580
self ._onErrorCb = callback
581
581
582
+ def SetNotifySubscriptionStillActiveCallback (self , callback : Callable ):
583
+ '''
584
+ Sets the callback function that gets invoked when a report data message is sent. The callback
585
+ is expected to have the following signature:
586
+ def Callback()
587
+ '''
588
+ if callback is not None :
589
+ self ._readTransaction .register_notify_subscription_still_active_callback (callback )
590
+
582
591
@property
583
592
def OnAttributeChangeCb (self ) -> Callable [[TypedAttributePath , SubscriptionTransaction ], None ]:
584
593
return self ._onAttributeChangeCb
@@ -680,52 +689,13 @@ def __init__(self, future: Future, eventLoop, devCtrl, returnClusterObject: bool
680
689
self ._pReadClient = None
681
690
self ._pReadCallback = None
682
691
self ._resultError = None
683
-
684
- print ("\n \n \n " )
685
- print (f"AsyncReadTransaction - __init__" )
686
- print (f"self._event_loop: { self ._event_loop } " )
687
- print (f"self._future: { self ._future } " )
688
- print (f"self._subscription_handler: { self ._subscription_handler } " )
689
- print (f"self._events: { self ._events } " )
690
- print (f"self._devCtrl: { self ._devCtrl } " )
691
- print (f"self._cache: { self ._cache } " )
692
- print (f"self._changedPathSet: { self ._changedPathSet } " )
693
- print (f"self._pReadClient: { self ._pReadClient } " )
694
- print (f"self._pReadCallback: { self ._pReadCallback } " )
695
- print (f"self._resultError: { self ._resultError } " )
696
- print ("\n \n \n " )
692
+ self ._notify_subscription_still_active_callback = None
697
693
698
694
def SetClientObjPointers (self , pReadClient , pReadCallback ):
699
695
self ._pReadClient = pReadClient
700
696
self ._pReadCallback = pReadCallback
701
- print ("\n \n \n " )
702
- print (f"AsyncReadTransaction - SetClientObjPointers" )
703
- print (f"self._event_loop: { self ._event_loop } " )
704
- print (f"self._future: { self ._future } " )
705
- print (f"self._subscription_handler: { self ._subscription_handler } " )
706
- print (f"self._events: { self ._events } " )
707
- print (f"self._devCtrl: { self ._devCtrl } " )
708
- print (f"self._cache: { self ._cache } " )
709
- print (f"self._changedPathSet: { self ._changedPathSet } " )
710
- print (f"self._pReadClient: { self ._pReadClient } " )
711
- print (f"self._pReadCallback: { self ._pReadCallback } " )
712
- print (f"self._resultError: { self ._resultError } " )
713
- print ("\n \n \n " )
714
697
715
698
def GetAllEventValues (self ):
716
- print ("\n \n \n " )
717
- print (f"AsyncReadTransaction - GetAllEventValues" )
718
- print (f"self._event_loop: { self ._event_loop } " )
719
- print (f"self._future: { self ._future } " )
720
- print (f"self._subscription_handler: { self ._subscription_handler } " )
721
- print (f"self._events: { self ._events } " )
722
- print (f"self._devCtrl: { self ._devCtrl } " )
723
- print (f"self._cache: { self ._cache } " )
724
- print (f"self._changedPathSet: { self ._changedPathSet } " )
725
- print (f"self._pReadClient: { self ._pReadClient } " )
726
- print (f"self._pReadCallback: { self ._pReadCallback } " )
727
- print (f"self._resultError: { self ._resultError } " )
728
- print ("\n \n \n " )
729
699
return self ._events
730
700
731
701
def handleAttributeData (self , path : AttributePathWithListIndex , dataVersion : int , status : int , data : bytes ):
@@ -742,20 +712,6 @@ def handleAttributeData(self, path: AttributePathWithListIndex, dataVersion: int
742
712
self ._cache .UpdateTLV (path , dataVersion , attributeValue )
743
713
self ._changedPathSet .add (path )
744
714
745
- print ("\n \n \n " )
746
- print (f"AsyncReadTransaction - handleAttributeData" )
747
- print (f"self._event_loop: { self ._event_loop } " )
748
- print (f"self._future: { self ._future } " )
749
- print (f"self._subscription_handler: { self ._subscription_handler } " )
750
- print (f"self._events: { self ._events } " )
751
- print (f"self._devCtrl: { self ._devCtrl } " )
752
- print (f"self._cache: { self ._cache } " )
753
- print (f"self._changedPathSet: { self ._changedPathSet } " )
754
- print (f"self._pReadClient: { self ._pReadClient } " )
755
- print (f"self._pReadCallback: { self ._pReadCallback } " )
756
- print (f"self._resultError: { self ._resultError } " )
757
- print ("\n \n \n " )
758
-
759
715
except Exception as ex :
760
716
logging .exception (ex )
761
717
@@ -796,39 +752,11 @@ def handleEventData(self, header: EventHeader, path: EventPath, data: bytes, sta
796
752
self ._subscription_handler .OnEventChangeCb (
797
753
eventResult , self ._subscription_handler )
798
754
799
- print ("\n \n \n " )
800
- print (f"AsyncReadTransaction - handleEventData" )
801
- print (f"self._event_loop: { self ._event_loop } " )
802
- print (f"self._future: { self ._future } " )
803
- print (f"self._subscription_handler: { self ._subscription_handler } " )
804
- print (f"self._events: { self ._events } " )
805
- print (f"self._devCtrl: { self ._devCtrl } " )
806
- print (f"self._cache: { self ._cache } " )
807
- print (f"self._changedPathSet: { self ._changedPathSet } " )
808
- print (f"self._pReadClient: { self ._pReadClient } " )
809
- print (f"self._pReadCallback: { self ._pReadCallback } " )
810
- print (f"self._resultError: { self ._resultError } " )
811
- print ("\n \n \n " )
812
-
813
755
except Exception as ex :
814
756
logging .exception (ex )
815
757
816
758
def handleError (self , chipError : PyChipError ):
817
759
self ._resultError = chipError .code
818
-
819
- print ("\n \n \n " )
820
- print (f"AsyncReadTransaction - handleError" )
821
- print (f"self._event_loop: { self ._event_loop } " )
822
- print (f"self._future: { self ._future } " )
823
- print (f"self._subscription_handler: { self ._subscription_handler } " )
824
- print (f"self._events: { self ._events } " )
825
- print (f"self._devCtrl: { self ._devCtrl } " )
826
- print (f"self._cache: { self ._cache } " )
827
- print (f"self._changedPathSet: { self ._changedPathSet } " )
828
- print (f"self._pReadClient: { self ._pReadClient } " )
829
- print (f"self._pReadCallback: { self ._pReadCallback } " )
830
- print (f"self._resultError: { self ._resultError } " )
831
- print ("\n \n \n " )
832
760
833
761
def _handleSubscriptionEstablished (self , subscriptionId ):
834
762
if not self ._future .done ():
@@ -844,20 +772,6 @@ def _handleSubscriptionEstablished(self, subscriptionId):
844
772
else :
845
773
self ._subscription_handler ._onResubscriptionSucceededCb (self ._subscription_handler )
846
774
847
- print ("\n \n \n " )
848
- print (f"AsyncReadTransaction - _handleSubscriptionEstablished" )
849
- print (f"self._event_loop: { self ._event_loop } " )
850
- print (f"self._future: { self ._future } " )
851
- print (f"self._subscription_handler: { self ._subscription_handler } " )
852
- print (f"self._events: { self ._events } " )
853
- print (f"self._devCtrl: { self ._devCtrl } " )
854
- print (f"self._cache: { self ._cache } " )
855
- print (f"self._changedPathSet: { self ._changedPathSet } " )
856
- print (f"self._pReadClient: { self ._pReadClient } " )
857
- print (f"self._pReadCallback: { self ._pReadCallback } " )
858
- print (f"self._resultError: { self ._resultError } " )
859
- print ("\n \n \n " )
860
-
861
775
def handleSubscriptionEstablished (self , subscriptionId ):
862
776
self ._event_loop .call_soon_threadsafe (
863
777
self ._handleSubscriptionEstablished , subscriptionId )
@@ -873,53 +787,12 @@ def handleResubscriptionAttempted(self, terminationCause: PyChipError, nextResub
873
787
self ._subscription_handler ._onResubscriptionAttemptedCb ,
874
788
self ._subscription_handler , terminationCause .code , nextResubscribeIntervalMsec )
875
789
876
- print ("\n \n \n " )
877
- print (f"AsyncReadTransaction - handleResubscriptionAttempted" )
878
- print (f"self._event_loop: { self ._event_loop } " )
879
- print (f"self._future: { self ._future } " )
880
- print (f"self._subscription_handler: { self ._subscription_handler } " )
881
- print (f"self._events: { self ._events } " )
882
- print (f"self._devCtrl: { self ._devCtrl } " )
883
- print (f"self._cache: { self ._cache } " )
884
- print (f"self._changedPathSet: { self ._changedPathSet } " )
885
- print (f"self._pReadClient: { self ._pReadClient } " )
886
- print (f"self._pReadCallback: { self ._pReadCallback } " )
887
- print (f"self._resultError: { self ._resultError } " )
888
- print ("\n \n \n " )
889
-
890
790
def _handleReportBegin (self ):
891
- print ("\n \n \n " )
892
- print (f"AsyncReadTransaction - _handleReportBegin" )
893
- print (f"self._event_loop: { self ._event_loop } " )
894
- print (f"self._future: { self ._future } " )
895
- print (f"self._subscription_handler: { self ._subscription_handler } " )
896
- print (f"self._events: { self ._events } " )
897
- print (f"self._devCtrl: { self ._devCtrl } " )
898
- print (f"self._cache: { self ._cache } " )
899
- print (f"self._changedPathSet: { self ._changedPathSet } " )
900
- print (f"self._pReadClient: { self ._pReadClient } " )
901
- print (f"self._pReadCallback: { self ._pReadCallback } " )
902
- print (f"self._resultError: { self ._resultError } " )
903
- print ("\n \n \n " )
904
791
pass
905
792
906
793
def _handleReportEnd (self ):
907
794
self ._cache .UpdateCachedData (self ._changedPathSet )
908
795
909
- print ("\n \n \n " )
910
- print (f"AsyncReadTransaction - _handleReportEnd" )
911
- print (f"self._event_loop: { self ._event_loop } " )
912
- print (f"self._future: { self ._future } " )
913
- print (f"self._subscription_handler: { self ._subscription_handler } " )
914
- print (f"self._events: { self ._events } " )
915
- print (f"self._devCtrl: { self ._devCtrl } " )
916
- print (f"self._cache: { self ._cache } " )
917
- print (f"self._changedPathSet: { self ._changedPathSet } " )
918
- print (f"self._pReadClient: { self ._pReadClient } " )
919
- print (f"self._pReadCallback: { self ._pReadCallback } " )
920
- print (f"self._resultError: { self ._resultError } " )
921
- print ("\n \n \n " )
922
-
923
796
if (self ._subscription_handler is not None ):
924
797
for change in self ._changedPathSet :
925
798
try :
@@ -950,21 +823,6 @@ def _handleDone(self):
950
823
else :
951
824
self ._future .set_result (AsyncReadTransaction .ReadResponse (
952
825
attributes = self ._cache .attributeCache , events = self ._events , tlvAttributes = self ._cache .attributeTLVCache ))
953
-
954
- print ("\n \n \n " )
955
- print (f"AsyncReadTransaction - _handleDone" )
956
- print (f"self._event_loop: { self ._event_loop } " )
957
- print (f"self._future: { self ._future } " )
958
- print (f"self._subscription_handler: { self ._subscription_handler } " )
959
- print (f"self._events: { self ._events } " )
960
- print (f"self._devCtrl: { self ._devCtrl } " )
961
- print (f"self._cache: { self ._cache } " )
962
- print (f"self._changedPathSet: { self ._changedPathSet } " )
963
- print (f"self._pReadClient: { self ._pReadClient } " )
964
- print (f"self._pReadCallback: { self ._pReadCallback } " )
965
- print (f"self._resultError: { self ._resultError } " )
966
- print ("\n \n \n " )
967
-
968
826
#
969
827
# Decrement the ref on ourselves to match the increment that happened at allocation.
970
828
# This happens synchronously as part of handling done to ensure the object remains valid
@@ -982,24 +840,14 @@ def handleReportEnd(self):
982
840
self ._handleReportEnd ()
983
841
984
842
def _handleNotifySubscriptionStillActive (self ):
985
- pass
843
+ if self ._notify_subscription_still_active_callback :
844
+ self ._notify_subscription_still_active_callback ()
986
845
987
846
def handleNotifySubscriptionStillActive (self ):
988
- print ("\n \n \n \n \n \n \n \n \n \n \n " )
989
- print (f"closure.handleNotifySubscriptionStillActive" )
990
- print (f"\t \t AsyncReadTransaction - _handleReportBegin" )
991
- print (f"\t \t self._event_loop: { self ._event_loop } " )
992
- print (f"\t \t self._future: { self ._future } " )
993
- print (f"\t \t self._subscription_handler: { self ._subscription_handler } " )
994
- print (f"\t \t self._events: { self ._events } " )
995
- print (f"\t \t self._devCtrl: { self ._devCtrl } " )
996
- print (f"\t \t self._cache: { self ._cache } " )
997
- print (f"\t \t self._changedPathSet: { self ._changedPathSet } " )
998
- print (f"\t \t self._pReadClient: { self ._pReadClient } " )
999
- print (f"\t \t self._pReadCallback: { self ._pReadCallback } " )
1000
- print (f"\t \t self._resultError: { self ._resultError } " )
1001
- print ("\n \n \n \n \n \n \n \n \n \n \n " )
1002
847
self ._handleNotifySubscriptionStillActive ()
848
+
849
+ def register_notify_subscription_still_active_callback (self , callback ):
850
+ self ._notify_subscription_still_active_callback = callback
1003
851
1004
852
1005
853
class AsyncWriteTransaction :
0 commit comments