Skip to content

Commit cdd8bd7

Browse files
committed
Add a cancel subscription method
1 parent d58723f commit cdd8bd7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/python_testing/matter_testing_support.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -410,18 +410,23 @@ def reset(self):
410410
self._attribute_reports[a] = []
411411
self._q = queue.Queue()
412412

413-
async def start(self, dev_ctrl, node_id: int, endpoint: int, fabric_filtered: bool = False, min_interval_sec: int = 0, max_interval_sec: int = 5) -> Any:
413+
async def start(self, dev_ctrl, node_id: int, endpoint: int, fabric_filtered: bool = False, min_interval_sec: int = 0, max_interval_sec: int = 5, keepSubscriptions: bool=True) -> Any:
414414
"""This starts a subscription for attributes on the specified node_id and endpoint. The cluster is specified when the class instance is created."""
415415
self._subscription = await dev_ctrl.ReadAttribute(
416416
nodeid=node_id,
417417
attributes=[(endpoint, self._expected_cluster)],
418418
reportInterval=(int(min_interval_sec), int(max_interval_sec)),
419419
fabricFiltered=fabric_filtered,
420-
keepSubscriptions=True
420+
keepSubscriptions=keepSubscriptions
421421
)
422422
self._subscription.SetAttributeUpdateCallback(self.__call__)
423423
return self._subscription
424424

425+
def cancel(self):
426+
"""This cancels a subscription."""
427+
self._subscription.Shutdown()
428+
self._subscription = None
429+
425430
def __call__(self, path: TypedAttributePath, transaction: SubscriptionTransaction):
426431
"""This is the subscription callback when an attribute report is received.
427432
It checks the report is from the expected_cluster and then posts it into the queue for later processing."""

0 commit comments

Comments
 (0)