diff --git a/appdaemon/entity.py b/appdaemon/entity.py new file mode 100644 index 0000000..246e38f --- /dev/null +++ b/appdaemon/entity.py @@ -0,0 +1,26 @@ +from appdaemon import utils + + +class Entity: + @utils.sync_decorator + async def get_callbacks(self, limit_to_app: str = None) -> dict[str, dict[str, Any]]: + async with self.AD.callbacks.callbacks_lock: + return { + handle: { + 'app_name': cb_info['name'], + 'function': cb_info['function'].__name__, + **cb_info["kwargs"] + } + for app_name, app_callbacks in self.AD.callbacks.callbacks.items() + if limit_to_app is None or app_name == limit_to_app + for handle, cb_info in app_callbacks.items() + if self.namespace == cb_info['namespace'] + and cb_info["type"] == "state" + and cb_info.get('entity') == self.entity_id + } + + @utils.sync_decorator + async def cancel_callbacks(self, all: bool = False): + for handle, info in (await self.get_callbacks()).items(): + if all or self.name == info['app_name']: + await self.AD.state.cancel_state_callback(handle, info['app_name'])