Skip to content

Commit f6f873b

Browse files
authored
[Python] Fix subscription error handling and re-subscription (project-chip#34372)
* [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.
1 parent 78807cd commit f6f873b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/controller/python/chip/clusters/Attribute.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,8 @@ def handleEventData(self, header: EventHeader, path: EventPath, data: bytes, sta
720720
LOGGER.exception(ex)
721721

722722
def handleError(self, chipError: PyChipError):
723+
if self._subscription_handler:
724+
self._subscription_handler.OnErrorCb(chipError.code, self._subscription_handler)
723725
self._resultError = chipError
724726

725727
def _handleSubscriptionEstablished(self, subscriptionId):
@@ -728,6 +730,7 @@ def _handleSubscriptionEstablished(self, subscriptionId):
728730
self, subscriptionId, self._devCtrl)
729731
self._future.set_result(self._subscription_handler)
730732
else:
733+
self._subscription_handler._subscriptionId = subscriptionId
731734
if self._subscription_handler._onResubscriptionSucceededCb is not None:
732735
if (self._subscription_handler._onResubscriptionSucceededCb_isAsync):
733736
self._event_loop.create_task(
@@ -779,10 +782,7 @@ def _handleDone(self):
779782
#
780783
if not self._future.done():
781784
if self._resultError is not None:
782-
if self._subscription_handler:
783-
self._subscription_handler.OnErrorCb(self._resultError.code, self._subscription_handler)
784-
else:
785-
self._future.set_exception(self._resultError.to_exception())
785+
self._future.set_exception(self._resultError.to_exception())
786786
else:
787787
self._future.set_result(AsyncReadTransaction.ReadResponse(
788788
attributes=self._cache.attributeCache, events=self._events, tlvAttributes=self._cache.attributeTLVCache))

0 commit comments

Comments
 (0)