reorg
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
import asyncio
|
||||
from cgitb import handler
|
||||
from copy import deepcopy
|
||||
from logging import Logger
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
import appdaemon.utils as utils
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from appdaemon.appdaemon import AppDaemon
|
||||
|
||||
@@ -46,16 +43,18 @@ class Callbacks:
|
||||
async def cancel_callback(self, handle: str, name: str, silent: bool = False):
|
||||
async with self.callbacks_lock:
|
||||
if (callbacks := self.callbacks.get(name)) \
|
||||
and (callback := callbacks.pop(handle, False)):
|
||||
and (callback := callbacks.pop(handle, False)):
|
||||
await self.AD.state.remove_entity("admin", f"{callback['type']}_callback.{handle}")
|
||||
return True
|
||||
elif not silent:
|
||||
self.logger.warning(f"Invalid callback handle '{handle}' in cancel_callback()")
|
||||
self.logger.warning(f"Invalid callback handle '{
|
||||
handle}' in cancel_callback()")
|
||||
|
||||
async def cancel_all_callbacks(self, name: str, silent: bool = False):
|
||||
async with self.callbacks_lock:
|
||||
if callbacks := self.callbacks.pop(name, False):
|
||||
self.logger.debug("Clearing %s callbacks for %s", len(callbacks), name)
|
||||
self.logger.debug(
|
||||
"Clearing %s callbacks for %s", len(callbacks), name)
|
||||
for handle, cb_info in callbacks.items():
|
||||
cb_type: Literal["event", "state", "log"] = cb_info['type']
|
||||
await self.AD.state.remove_entity("admin", f"{cb_type}_callback.{handle}")
|
||||
Reference in New Issue
Block a user