Skip to content

Commit

Permalink
Updates AttributeChangeCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-marquez-csa committed May 22, 2024
1 parent d92f839 commit 28d683d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/python_testing/matter_testing_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,25 +317,29 @@ def __init__(self, expected_attribute: ClusterObjects.ClusterAttributeDescriptor
self._expected_attribute = expected_attribute

def __call__(self, path: TypedAttributePath, transaction: SubscriptionTransaction):
if path.AttributeType == self._expected_attribute:
q = (path, transaction)
logging.info(f'[callback] Got subscription report for {path.AttributeType}')
self._output.put(q)
else:
logging.error(f"Expected attribute {self._expected_attribute} mismatch: {path.AttributeType}")
"""This is the subscription callback when an attribute is updated.
It checks the passed in attribute is the same as the subscribed to attribute and
then posts it into the queue for later processing."""

asserts.assert_equal(path.AttributeType, self._expected_attribute,
f"[AttributeChangeCallback] Attribute mismatch. Expected: {self._expected_attribute}, received: {path.AttributeType}")
logging.info(f"[AttributeChangeCallback] Attribute update callback for {path.AttributeType}")
q = (path, transaction)
self._output.put(q)

def wait_for_report(self):
try:
path, transaction = self._output.get(block=True, timeout=10)
except queue.Empty:
asserts.fail(f"Failed to receive a report for the attribute change for {self._expected_attribute}")
asserts.fail(f"[AttributeChangeCallback] Failed to receive a report for the {self._expected_attribute} attribute change")

asserts.assert_equal(path.AttributeType, self._expected_attribute,
f"Received incorrect attribute report. Expected: {self._expected_attribute}, received: {path.AttributeType}")
f"[AttributeChangeCallback] Received incorrect report. Expected: {self._expected_attribute}, received: {path.AttributeType}")
try:
transaction.GetAttribute(path)
attribute_value = transaction.GetAttribute(path)
logging.info(f"[AttributeChangeCallback] Got attribute subscription report. Attribute {path.AttributeType}. Updated value: {attribute_value}. SubscriptionId: {transaction.subscriptionId}")
except KeyError:
asserts.fail("Attribute {expected_attribute} not found in returned report")
asserts.fail("[AttributeChangeCallback] Attribute {expected_attribute} not found in returned report")


class InternalTestRunnerHooks(TestRunnerHooks):
Expand Down

0 comments on commit 28d683d

Please sign in to comment.