Skip to content

Commit

Permalink
[Python] Fix subscription error handling and re-subscription (#34372)
Browse files Browse the repository at this point in the history
* [Python] Fix error callback in AsyncReadTransaction

Currently the error callback is only called when the future is not done
yet and the subscription handler exists. However, the subscription
handler only gets initialized on successful subscription, which is also
where the future gets set to done. So there is no situation where the
error callback is being called, currently.

Fix this by calling the error callback straight from the Matter SDK
Thread when the subscription handler exists. This makes it independent
of the future.

* [Python] Update subscription id on re-subscribe

Make sure we update the subscription ID in the subscription established
callback when the subscription handler already exists. This makes sure
that we have the correct subscription ID stored in the
`SubscriptionTransaction` object after successfully re-subscribe too.
  • Loading branch information
agners authored and pull[bot] committed Sep 17, 2024
1 parent 846a9da commit 35cb037
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/controller/python/chip/clusters/Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ def handleEventData(self, header: EventHeader, path: EventPath, data: bytes, sta
LOGGER.exception(ex)

def handleError(self, chipError: PyChipError):
if self._subscription_handler:
self._subscription_handler.OnErrorCb(chipError.code, self._subscription_handler)
self._resultError = chipError

def _handleSubscriptionEstablished(self, subscriptionId):
Expand All @@ -728,6 +730,7 @@ def _handleSubscriptionEstablished(self, subscriptionId):
self, subscriptionId, self._devCtrl)
self._future.set_result(self._subscription_handler)
else:
self._subscription_handler._subscriptionId = subscriptionId
if self._subscription_handler._onResubscriptionSucceededCb is not None:
if (self._subscription_handler._onResubscriptionSucceededCb_isAsync):
self._event_loop.create_task(
Expand Down Expand Up @@ -779,10 +782,7 @@ def _handleDone(self):
#
if not self._future.done():
if self._resultError is not None:
if self._subscription_handler:
self._subscription_handler.OnErrorCb(self._resultError.code, self._subscription_handler)
else:
self._future.set_exception(self._resultError.to_exception())
self._future.set_exception(self._resultError.to_exception())
else:
self._future.set_result(AsyncReadTransaction.ReadResponse(
attributes=self._cache.attributeCache, events=self._events, tlvAttributes=self._cache.attributeTLVCache))
Expand Down

0 comments on commit 35cb037

Please sign in to comment.