diff --git a/src/controller/python/chip/clusters/Attribute.py b/src/controller/python/chip/clusters/Attribute.py index fe62f3f11d2f81..4f4dd9c7913221 100644 --- a/src/controller/python/chip/clusters/Attribute.py +++ b/src/controller/python/chip/clusters/Attribute.py @@ -553,7 +553,7 @@ def SetAttributeUpdateCallback( if callback is not None: self._onAttributeChangeCb = callback - def SetEventUpdateCallback(self, callback: Callable[[EventReadResult, SubscriptionTransaction], None]): + def SetEventUpdateCallback(self, callback: Callable[[EventReadResult, SubscriptionTransaction], Union[None, Awaitable[None]]]): if callback is not None: self._onEventChangeCb = callback @@ -570,7 +570,7 @@ def OnAttributeChangeCb(self) -> Callable[[TypedAttributePath, SubscriptionTrans return self._onAttributeChangeCb @property - def OnEventChangeCb(self) -> Callable[[EventReadResult, SubscriptionTransaction], None]: + def OnEventChangeCb(self) -> Callable[[EventReadResult, SubscriptionTransaction], Union[None, Awaitable[None]]]: return self._onEventChangeCb @property @@ -724,9 +724,14 @@ def handleEventData(self, header: EventHeader, path: EventPath, data: bytes, sta Header=header, Data=eventValue, Status=chip.interaction_model.Status(status)) self._events.append(eventResult) - if (self._subscription_handler is not None): - self._subscription_handler.OnEventChangeCb( - eventResult, self._subscription_handler) + if self._subscription_handler is not None: + callback = self._subscription_handler.OnEventChangeCb + if inspect.iscoroutinefunction(callback): + asyncio.run_coroutine_threadsafe(callback(), self._event_loop) + else: + self._event_loop.call_soon_threadsafe( + self._subscription_handler.OnEventChangeCb, + eventResult, self._subscription_handler) except Exception as ex: logging.exception(ex)