Skip to content

Commit 28d683d

Browse files
Updates AttributeChangeCallback
1 parent d92f839 commit 28d683d

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/python_testing/matter_testing_support.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,29 @@ def __init__(self, expected_attribute: ClusterObjects.ClusterAttributeDescriptor
317317
self._expected_attribute = expected_attribute
318318

319319
def __call__(self, path: TypedAttributePath, transaction: SubscriptionTransaction):
320-
if path.AttributeType == self._expected_attribute:
321-
q = (path, transaction)
322-
logging.info(f'[callback] Got subscription report for {path.AttributeType}')
323-
self._output.put(q)
324-
else:
325-
logging.error(f"Expected attribute {self._expected_attribute} mismatch: {path.AttributeType}")
320+
"""This is the subscription callback when an attribute is updated.
321+
It checks the passed in attribute is the same as the subscribed to attribute and
322+
then posts it into the queue for later processing."""
323+
324+
asserts.assert_equal(path.AttributeType, self._expected_attribute,
325+
f"[AttributeChangeCallback] Attribute mismatch. Expected: {self._expected_attribute}, received: {path.AttributeType}")
326+
logging.info(f"[AttributeChangeCallback] Attribute update callback for {path.AttributeType}")
327+
q = (path, transaction)
328+
self._output.put(q)
326329

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

333336
asserts.assert_equal(path.AttributeType, self._expected_attribute,
334-
f"Received incorrect attribute report. Expected: {self._expected_attribute}, received: {path.AttributeType}")
337+
f"[AttributeChangeCallback] Received incorrect report. Expected: {self._expected_attribute}, received: {path.AttributeType}")
335338
try:
336-
transaction.GetAttribute(path)
339+
attribute_value = transaction.GetAttribute(path)
340+
logging.info(f"[AttributeChangeCallback] Got attribute subscription report. Attribute {path.AttributeType}. Updated value: {attribute_value}. SubscriptionId: {transaction.subscriptionId}")
337341
except KeyError:
338-
asserts.fail("Attribute {expected_attribute} not found in returned report")
342+
asserts.fail("[AttributeChangeCallback] Attribute {expected_attribute} not found in returned report")
339343

340344

341345
class InternalTestRunnerHooks(TestRunnerHooks):

0 commit comments

Comments
 (0)