|
| 1 | +From 5ab917909f15fec74778cc2e805b254aaccef1c3 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Stefan Agner <stefan@agner.ch> |
| 3 | +Date: Thu, 18 Jul 2024 07:39:38 +0100 |
| 4 | +Subject: [PATCH] [Python] Fix subscription error handling and re-subscription |
| 5 | + (#34372) |
| 6 | + |
| 7 | +* [Python] Fix error callback in AsyncReadTransaction |
| 8 | + |
| 9 | +Currently the error callback is only called when the future is not done |
| 10 | +yet and the subscription handler exists. However, the subscription |
| 11 | +handler only gets initialized on successful subscription, which is also |
| 12 | +where the future gets set to done. So there is no situation where the |
| 13 | +error callback is being called, currently. |
| 14 | + |
| 15 | +Fix this by calling the error callback straight from the Matter SDK |
| 16 | +Thread when the subscription handler exists. This makes it independent |
| 17 | +of the future. |
| 18 | + |
| 19 | +* [Python] Update subscription id on re-subscribe |
| 20 | + |
| 21 | +Make sure we update the subscription ID in the subscription established |
| 22 | +callback when the subscription handler already exists. This makes sure |
| 23 | +that we have the correct subscription ID stored in the |
| 24 | +`SubscriptionTransaction` object after successfully re-subscribe too. |
| 25 | +--- |
| 26 | + src/controller/python/chip/clusters/Attribute.py | 8 ++++---- |
| 27 | + 1 file changed, 4 insertions(+), 4 deletions(-) |
| 28 | + |
| 29 | +diff --git a/src/controller/python/chip/clusters/Attribute.py b/src/controller/python/chip/clusters/Attribute.py |
| 30 | +index 31e8444c70..63ca02d8df 100644 |
| 31 | +--- a/src/controller/python/chip/clusters/Attribute.py |
| 32 | ++++ b/src/controller/python/chip/clusters/Attribute.py |
| 33 | +@@ -743,6 +743,8 @@ class AsyncReadTransaction: |
| 34 | + LOGGER.exception(ex) |
| 35 | + |
| 36 | + def handleError(self, chipError: PyChipError): |
| 37 | ++ if self._subscription_handler: |
| 38 | ++ self._subscription_handler.OnErrorCb(chipError.code, self._subscription_handler) |
| 39 | + self._resultError = chipError |
| 40 | + |
| 41 | + def _handleSubscriptionEstablished(self, subscriptionId): |
| 42 | +@@ -751,6 +753,7 @@ class AsyncReadTransaction: |
| 43 | + self, subscriptionId, self._devCtrl) |
| 44 | + self._future.set_result(self._subscription_handler) |
| 45 | + else: |
| 46 | ++ self._subscription_handler._subscriptionId = subscriptionId |
| 47 | + if self._subscription_handler._onResubscriptionSucceededCb is not None: |
| 48 | + if (self._subscription_handler._onResubscriptionSucceededCb_isAsync): |
| 49 | + self._event_loop.create_task( |
| 50 | +@@ -807,10 +810,7 @@ class AsyncReadTransaction: |
| 51 | + # |
| 52 | + if not self._future.done(): |
| 53 | + if self._resultError is not None: |
| 54 | +- if self._subscription_handler: |
| 55 | +- self._subscription_handler.OnErrorCb(self._resultError.code, self._subscription_handler) |
| 56 | +- else: |
| 57 | +- self._future.set_exception(self._resultError.to_exception()) |
| 58 | ++ self._future.set_exception(self._resultError.to_exception()) |
| 59 | + else: |
| 60 | + self._future.set_result(AsyncReadTransaction.ReadResponse( |
| 61 | + attributes=self._cache.attributeCache, events=self._events, tlvAttributes=self._cache.attributeTLVCache)) |
| 62 | +-- |
| 63 | +2.45.2 |
| 64 | + |
0 commit comments