added entity callback cancellation

This commit is contained in:
John Lancaster
2024-10-16 03:57:40 +00:00
parent 5e458aca41
commit 9121d1ef04

26
appdaemon/entity.py Normal file
View File

@@ -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'])