adding the unmarkupformatter to all handlers of Appdaemon
This commit is contained in:
10
button.py
10
button.py
@@ -2,7 +2,8 @@ import json
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from appdaemon.plugins.mqtt.mqttapi import Mqtt
|
from appdaemon.plugins.mqtt.mqttapi import Mqtt
|
||||||
from console import console, init_logging
|
from console import init_logging
|
||||||
|
|
||||||
from room_control import RoomController
|
from room_control import RoomController
|
||||||
|
|
||||||
|
|
||||||
@@ -32,10 +33,7 @@ class Button(Mqtt):
|
|||||||
topic = f'zigbee2mqtt/{name}'
|
topic = f'zigbee2mqtt/{name}'
|
||||||
# self.mqtt_subscribe(topic, namespace='mqtt')
|
# 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)
|
||||||
if self.rich:
|
self.log(f'MQTT topic [blue]{topic}[/] controls app [green]{self.app.name}[/]')
|
||||||
self.log(f'MQTT topic [blue]{topic}[/] controls app [green]{self.app.name}[/]')
|
|
||||||
else:
|
|
||||||
self.log(f'MQTT topic "{topic}" controls app {self.app.name}')
|
|
||||||
|
|
||||||
def handle_button(self, event_name, data, kwargs):
|
def handle_button(self, event_name, data, kwargs):
|
||||||
try:
|
try:
|
||||||
@@ -51,7 +49,7 @@ class Button(Mqtt):
|
|||||||
|
|
||||||
def handle_action(self, action: str):
|
def handle_action(self, action: str):
|
||||||
if isinstance(action, str):
|
if isinstance(action, str):
|
||||||
action_str = f' [yellow]{action.upper()}[/] ' if self.rich else f' {action.upper()} '
|
action_str = f' [yellow]{action.upper()}[/] '
|
||||||
|
|
||||||
if action == 'single':
|
if action == 'single':
|
||||||
self.log(action_str.center(80, '='))
|
self.log(action_str.center(80, '='))
|
||||||
|
|||||||
@@ -36,9 +36,11 @@ def create_handler() -> RichHandler:
|
|||||||
|
|
||||||
|
|
||||||
def init_logging(self: ADAPI, level):
|
def init_logging(self: ADAPI, level):
|
||||||
stream_handler = logging.getLogger('AppDaemon').handlers[0]
|
for h in logging.getLogger('AppDaemon').handlers:
|
||||||
og_formatter = stream_handler.formatter
|
og_formatter = h.formatter
|
||||||
stream_handler.setFormatter(UnMarkupFormatter(fmt=og_formatter._fmt, datefmt=og_formatter.datefmt, style='{'))
|
h.setFormatter(
|
||||||
|
UnMarkupFormatter(fmt=og_formatter._fmt, datefmt=og_formatter.datefmt, style='{')
|
||||||
|
)
|
||||||
|
|
||||||
if not any(isinstance(h, RichHandler) for h in self.logger.handlers):
|
if not any(isinstance(h, RichHandler) for h in self.logger.handlers):
|
||||||
self.logger.propagate = False
|
self.logger.propagate = False
|
||||||
|
|||||||
Reference in New Issue
Block a user