reorg
This commit is contained in:
@@ -1,11 +1,8 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from cgitb import handler
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from logging import Logger
|
from logging import Logger
|
||||||
from typing import TYPE_CHECKING, Any, Literal
|
from typing import TYPE_CHECKING, Any, Literal
|
||||||
|
|
||||||
import appdaemon.utils as utils
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from appdaemon.appdaemon import AppDaemon
|
from appdaemon.appdaemon import AppDaemon
|
||||||
|
|
||||||
@@ -35,27 +32,29 @@ class Callbacks:
|
|||||||
self.diag = ad.logging.get_diag()
|
self.diag = ad.logging.get_diag()
|
||||||
self.callbacks = {}
|
self.callbacks = {}
|
||||||
self.callbacks_lock = asyncio.Lock()
|
self.callbacks_lock = asyncio.Lock()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Diagnostic
|
# Diagnostic
|
||||||
#
|
#
|
||||||
|
|
||||||
async def add_callback(self):
|
async def add_callback(self):
|
||||||
return
|
return
|
||||||
|
|
||||||
async def cancel_callback(self, handle: str, name: str, silent: bool = False):
|
async def cancel_callback(self, handle: str, name: str, silent: bool = False):
|
||||||
async with self.callbacks_lock:
|
async with self.callbacks_lock:
|
||||||
if (callbacks := self.callbacks.get(name)) \
|
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}")
|
await self.AD.state.remove_entity("admin", f"{callback['type']}_callback.{handle}")
|
||||||
return True
|
return True
|
||||||
elif not silent:
|
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 def cancel_all_callbacks(self, name: str, silent: bool = False):
|
||||||
async with self.callbacks_lock:
|
async with self.callbacks_lock:
|
||||||
if callbacks := self.callbacks.pop(name, False):
|
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():
|
for handle, cb_info in callbacks.items():
|
||||||
cb_type: Literal["event", "state", "log"] = cb_info['type']
|
cb_type: Literal["event", "state", "log"] = cb_info['type']
|
||||||
await self.AD.state.remove_entity("admin", f"{cb_type}_callback.{handle}")
|
await self.AD.state.remove_entity("admin", f"{cb_type}_callback.{handle}")
|
||||||
@@ -81,7 +80,7 @@ class Callbacks:
|
|||||||
}
|
}
|
||||||
for app_name, app_callbacks in self.callbacks.items()
|
for app_name, app_callbacks in self.callbacks.items()
|
||||||
}
|
}
|
||||||
|
|
||||||
async def get_callbacks(
|
async def get_callbacks(
|
||||||
self,
|
self,
|
||||||
namespace: str = 'all',
|
namespace: str = 'all',
|
||||||
Reference in New Issue
Block a user