simple fixes

This commit is contained in:
John Lancaster
2025-06-20 08:50:43 -05:00
parent ba043554dc
commit 475bdb9dd9
4 changed files with 25 additions and 21 deletions

View File

@@ -1,18 +1,22 @@
import logging
from enum import Enum from enum import Enum
GLOBAL_VAR = "Hello, World!" LOGGER = logging.getLogger('AppDaemon._globals')
def global_function(): GLOBAL_VAR = 'Hello, World!'
print('This is a global function.')
def global_function() -> None:
LOGGER.info('This is a global function.')
class GlobalClass: class GlobalClass:
def __init__(self): def __init__(self) -> None:
self.value = 'This is a global class instance.' self.value = 'This is a global class instance.'
def display(self): def display(self) -> None:
print(self.value) LOGGER.info(self.value)
class ModeSelect(Enum): class ModeSelect(Enum):

View File

@@ -12,17 +12,16 @@ simple_app:
# dependencies: # dependencies:
# - hello_world # - hello_world
base_app: base_app:
module: simple module: simple
class: BaseApp class: BaseApp
AppA: # AppA:
module: app_a # module: app_a
class: AppA # class: AppA
dependencies: # dependencies:
- AppB # This is only set to demonstrate forcing it to load after AppB # - AppB # This is only set to demonstrate forcing it to load after AppB
AppB: # AppB:
module: app_b # module: app_b
class: AppB # class: AppB

View File

@@ -10,14 +10,15 @@ from appdaemon.adapi import ADAPI
# fake/ # fake/
# SimpleApp # SimpleApp
class HelloWorld(ADAPI): class HelloWorld(ADAPI):
def initialize(self): def initialize(self) -> None:
self.log(f'{self.__class__.__name__} Initialized') self.log(f'{self.__class__.__name__} Initialized')
self.log('+' * 50) self.log('+' * 50)
# fake # fake
self.register_service("my_domain/my_exciting_service", self.my_exciting_cb) self.register_service('my_domain/my_exciting_service', self.my_exciting_cb)
def my_exciting_cb(self, *args: str, my_arg: int = 0, **kwargs: Any) -> Any: def my_exciting_cb(self, *args: str, my_arg: int = 0, **kwargs: Any) -> Any:
namespace, domain, service = args namespace, domain, service = args
self.log(f"Service {domain}/{service} in the {namespace} namepsace called with {kwargs}") self.log(f'Service {domain}/{service} in the {namespace} namepsace called with {kwargs}')
return 999 + my_arg return 999 + my_arg

View File

@@ -8,7 +8,7 @@ class SimpleApp(Hass):
match self.ping(): match self.ping():
case float() as ping: case float() as ping:
ping = utils.format_timedelta(ping) ping = utils.format_timedelta(ping)
self.log(f"{self.__class__.__name__} Initialized: {ping}") self.log(f'{self.__class__.__name__} Initialized: {ping}')
case _: case _:
pass pass
@@ -17,5 +17,5 @@ class BaseApp(ADBase):
def initialize(self) -> None: def initialize(self) -> None:
self.adapi = self.get_ad_api() self.adapi = self.get_ad_api()
self.log = self.adapi.log self.log = self.adapi.log
self.hassapi = self.get_plugin_api("HASS") self.hassapi = self.get_plugin_api('HASS')
assert isinstance(self.hassapi, Hass), "HASS API not available" assert isinstance(self.hassapi, Hass), 'HASS API not available'