This commit is contained in:
John Lancaster
2024-10-16 03:51:16 +00:00
parent 9ccbad58cf
commit 4dddc50c82

View File

@@ -82,16 +82,36 @@ class Callbacks:
for app_name, app_callbacks in self.callbacks.items()
}
async def get_callback_handles(self, app: str = 'all', type: str = 'all', entity_id: str = 'all'):
async def get_callbacks(
self,
namespace: str = 'all',
app: str = 'all',
type: str = 'all',
entity_id: str = 'all',
copy: bool = True,
) -> dict[str, dict[str, Any]]:
async with self.callbacks_lock:
handles = set(
handle
return {
handle: deepcopy(cb_info) if copy else cb_info
for app_name, app_callbacks in self.callbacks.items()
if app == 'all' or app == app_name
for handle, cb_info in app_callbacks.items()
if (type == 'all' or type == cb_info["type"])
and (entity_id == 'all' or entity_id == cb_info["entity"])
and (
namespace == 'all'
or namespace == 'global'
or cb_info["namespace"] == 'global'
or namespace == cb_info["namespace"]
)
self.logger.debug(f"Got {len(handles)} callbacks for app={app}, type={type}, entity_id={entity_id}")
return handles
}
async def get_callback_handles(
self,
namespace: str = 'all',
app: str = 'all',
type: str = 'all',
entity_id: str = 'all'
) -> set[str]:
callbacks = await self.get_callbacks(namespace, app, type, entity_id, copy=False)
return set(callbacks.keys())