improved logging

This commit is contained in:
John Lancaster
2024-04-27 13:41:29 -05:00
parent 6250b6b20c
commit 68edfde755
5 changed files with 50 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
import json
from dataclasses import dataclass
from logging import Logger
from typing import List
from appdaemon.plugins.mqtt.mqttapi import Mqtt
@@ -14,10 +15,11 @@ class Button(Mqtt):
button: str | List[str]
rich: bool = False
config: ButtonConfig
logger: Logger
async def initialize(self):
self.config = ButtonConfig(**self.args)
setup_component_logging(self)
self.logger = setup_component_logging(self)
self.app: RoomController = await self.get_app(self.args['app'])
self.log(f'Connected to AD app [room]{self.app.name}[/]', level='DEBUG')
@@ -34,7 +36,9 @@ class Button(Mqtt):
def setup_button(self, name: str):
topic = f'zigbee2mqtt/{name}'
# self.mqtt_subscribe(topic, namespace='mqtt')
self.listen_event(self.handle_button, 'MQTT_MESSAGE', topic=topic, namespace='mqtt', button=name)
self.listen_event(
self.handle_button, 'MQTT_MESSAGE', topic=topic, namespace='mqtt', button=name
)
self.log(f'MQTT topic [topic]{topic}[/] controls app [room]{self.app.name}[/]')
def handle_button(self, event_name, data, kwargs):