diff --git a/appdaemon.py b/appdaemon/appdaemon.py similarity index 100% rename from appdaemon.py rename to appdaemon/appdaemon.py diff --git a/callbacks.py b/appdaemon/callbacks.py similarity index 94% rename from callbacks.py rename to appdaemon/callbacks.py index 32cad9b..469fbbf 100644 --- a/callbacks.py +++ b/appdaemon/callbacks.py @@ -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 @@ -35,27 +32,29 @@ class Callbacks: self.diag = ad.logging.get_diag() self.callbacks = {} self.callbacks_lock = asyncio.Lock() - + # # Diagnostic # async def add_callback(self): return - + 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}") @@ -81,7 +80,7 @@ class Callbacks: } for app_name, app_callbacks in self.callbacks.items() } - + async def get_callbacks( self, namespace: str = 'all', diff --git a/state.py b/appdaemon/state.py similarity index 100% rename from state.py rename to appdaemon/state.py