Skip to content

Commit 56742f8

Browse files
Adds SetNotifySubscriptionStillActiveCallback
1 parent 3900053 commit 56742f8

File tree

2 files changed

+37
-182
lines changed

2 files changed

+37
-182
lines changed

src/controller/python/chip/clusters/Attribute.py

+15-167
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,15 @@ def SetErrorCallback(self, callback: Callable[[int, SubscriptionTransaction], No
579579
if callback is not None:
580580
self._onErrorCb = callback
581581

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+
582591
@property
583592
def OnAttributeChangeCb(self) -> Callable[[TypedAttributePath, SubscriptionTransaction], None]:
584593
return self._onAttributeChangeCb
@@ -680,52 +689,13 @@ def __init__(self, future: Future, eventLoop, devCtrl, returnClusterObject: bool
680689
self._pReadClient = None
681690
self._pReadCallback = None
682691
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
697693

698694
def SetClientObjPointers(self, pReadClient, pReadCallback):
699695
self._pReadClient = pReadClient
700696
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")
714697

715698
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")
729699
return self._events
730700

731701
def handleAttributeData(self, path: AttributePathWithListIndex, dataVersion: int, status: int, data: bytes):
@@ -742,20 +712,6 @@ def handleAttributeData(self, path: AttributePathWithListIndex, dataVersion: int
742712
self._cache.UpdateTLV(path, dataVersion, attributeValue)
743713
self._changedPathSet.add(path)
744714

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-
759715
except Exception as ex:
760716
logging.exception(ex)
761717

@@ -796,39 +752,11 @@ def handleEventData(self, header: EventHeader, path: EventPath, data: bytes, sta
796752
self._subscription_handler.OnEventChangeCb(
797753
eventResult, self._subscription_handler)
798754

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-
813755
except Exception as ex:
814756
logging.exception(ex)
815757

816758
def handleError(self, chipError: PyChipError):
817759
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")
832760

833761
def _handleSubscriptionEstablished(self, subscriptionId):
834762
if not self._future.done():
@@ -844,20 +772,6 @@ def _handleSubscriptionEstablished(self, subscriptionId):
844772
else:
845773
self._subscription_handler._onResubscriptionSucceededCb(self._subscription_handler)
846774

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-
861775
def handleSubscriptionEstablished(self, subscriptionId):
862776
self._event_loop.call_soon_threadsafe(
863777
self._handleSubscriptionEstablished, subscriptionId)
@@ -873,53 +787,12 @@ def handleResubscriptionAttempted(self, terminationCause: PyChipError, nextResub
873787
self._subscription_handler._onResubscriptionAttemptedCb,
874788
self._subscription_handler, terminationCause.code, nextResubscribeIntervalMsec)
875789

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-
890790
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")
904791
pass
905792

906793
def _handleReportEnd(self):
907794
self._cache.UpdateCachedData(self._changedPathSet)
908795

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-
923796
if (self._subscription_handler is not None):
924797
for change in self._changedPathSet:
925798
try:
@@ -950,21 +823,6 @@ def _handleDone(self):
950823
else:
951824
self._future.set_result(AsyncReadTransaction.ReadResponse(
952825
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-
968826
#
969827
# Decrement the ref on ourselves to match the increment that happened at allocation.
970828
# This happens synchronously as part of handling done to ensure the object remains valid
@@ -982,24 +840,14 @@ def handleReportEnd(self):
982840
self._handleReportEnd()
983841

984842
def _handleNotifySubscriptionStillActive(self):
985-
pass
843+
if self._notify_subscription_still_active_callback:
844+
self._notify_subscription_still_active_callback()
986845

987846
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\tAsyncReadTransaction - _handleReportBegin")
991-
print(f"\t\tself._event_loop: {self._event_loop}")
992-
print(f"\t\tself._future: {self._future}")
993-
print(f"\t\tself._subscription_handler: {self._subscription_handler}")
994-
print(f"\t\tself._events: {self._events}")
995-
print(f"\t\tself._devCtrl: {self._devCtrl}")
996-
print(f"\t\tself._cache: {self._cache}")
997-
print(f"\t\tself._changedPathSet: {self._changedPathSet}")
998-
print(f"\t\tself._pReadClient: {self._pReadClient}")
999-
print(f"\t\tself._pReadCallback: {self._pReadCallback}")
1000-
print(f"\t\tself._resultError: {self._resultError}")
1001-
print("\n\n\n\n\n\n\n\n\n\n\n")
1002847
self._handleNotifySubscriptionStillActive()
848+
849+
def register_notify_subscription_still_active_callback(self, callback):
850+
self._notify_subscription_still_active_callback = callback
1003851

1004852

1005853
class AsyncWriteTransaction:

src/python_testing/TC_IDM_4_3.py

+22-15
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import chip.clusters as Clusters
2525
from chip.ChipDeviceCtrl import ChipDeviceController
2626
from chip.clusters import ClusterObjects as ClusterObjects
27-
from chip.clusters.Attribute import AttributePath, TypedAttributePath
27+
from chip.clusters.Attribute import AttributePath, TypedAttributePath, AsyncReadTransaction
2828
from chip.exceptions import ChipStackError
2929
from chip.interaction_model import Status
3030
from matter_testing_support import AttributeChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main, EventChangeCallback
@@ -91,9 +91,13 @@ def steps_TC_IDM_4_3(self):
9191
# TestStep(21, "TH sends a subscription request to subscribe to all attributes from a specific cluster on all endpoints. AttributePath = [[Cluster = ClusterID]]. Set the MinIntervalFloor to some value say \"N\"(seconds). Change all or few of the attributes on the DUT",
9292
# "Verify that the DUT sends reports for all the attributes that have changed after N seconds.")
9393
]
94-
94+
95+
def on_notify_subscription_still_active(self):
96+
print("NotifyLogic")
97+
9598
@async_test_body
9699
async def test_TC_IDM_4_3(self):
100+
print("Hey there")
97101

98102
# Test setup
99103
node_label_attr = Clusters.BasicInformation.Attributes.NodeLabel
@@ -111,22 +115,25 @@ async def test_TC_IDM_4_3(self):
111115
reportInterval=(3, 5),
112116
keepSubscriptions=False
113117
)
114-
115-
116-
117-
118+
119+
120+
121+
122+
123+
124+
125+
sub_th_step1a.SetNotifySubscriptionStillActiveCallback(self.on_notify_subscription_still_active)
126+
118127
secs = 60
119128
print(f"\n\n\n\n\nTime to sleep {secs} second(s)")
120129
time.sleep(secs)
121130
print(f"Rise and shine after {secs} second(s)\n\n\n\n\n")
122131

123-
124-
125-
126-
127-
128-
129-
132+
133+
134+
135+
136+
130137

131138
# Verify that the subscription is activated between TH and DUT
132139
# Verify on the TH, a report data message is received.
@@ -150,14 +157,14 @@ async def test_TC_IDM_4_3(self):
150157
# Set Attribute Update Callback
151158
node_label_update_cb = AttributeChangeCallback(node_label_attr)
152159
sub_th_step1a.SetAttributeUpdateCallback(node_label_update_cb)
153-
160+
154161
# Modify attribute value
155162
new_node_label_write = "NewNodeLabel_11001100"
156163
await TH.WriteAttribute(
157164
self.dut_node_id,
158165
[(0, node_label_attr(value=new_node_label_write))]
159166
)
160-
167+
161168
node_label_update_cb.wait_for_report()
162169

163170

0 commit comments

Comments
 (0)