Skip to content

Commit

Permalink
Add a cancel subscription method
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterC1965 committed Aug 22, 2024
1 parent d58723f commit cdd8bd7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/python_testing/matter_testing_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,23 @@ def reset(self):
self._attribute_reports[a] = []
self._q = queue.Queue()

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:
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:
"""This starts a subscription for attributes on the specified node_id and endpoint. The cluster is specified when the class instance is created."""
self._subscription = await dev_ctrl.ReadAttribute(
nodeid=node_id,
attributes=[(endpoint, self._expected_cluster)],
reportInterval=(int(min_interval_sec), int(max_interval_sec)),
fabricFiltered=fabric_filtered,
keepSubscriptions=True
keepSubscriptions=keepSubscriptions
)
self._subscription.SetAttributeUpdateCallback(self.__call__)
return self._subscription

def cancel(self):
"""This cancels a subscription."""
self._subscription.Shutdown()
self._subscription = None

def __call__(self, path: TypedAttributePath, transaction: SubscriptionTransaction):
"""This is the subscription callback when an attribute report is received.
It checks the report is from the expected_cluster and then posts it into the queue for later processing."""
Expand Down

0 comments on commit cdd8bd7

Please sign in to comment.