more rich formatting
This commit is contained in:
@@ -31,7 +31,7 @@ class Button(Mqtt):
|
||||
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.log(f'MQTT topic [blue]{topic}[/] controls app [green]{self.app.name}[/]')
|
||||
self.log(f'MQTT topic [topic]{topic}[/] controls app [room]{self.app.name}[/]')
|
||||
|
||||
def handle_button(self, event_name, data, kwargs):
|
||||
try:
|
||||
@@ -42,15 +42,12 @@ class Button(Mqtt):
|
||||
except KeyError:
|
||||
return
|
||||
else:
|
||||
if action != '':
|
||||
if isinstance(action, str) and action != '':
|
||||
self.log(f'Action: [yellow]{action}[/]')
|
||||
self.handle_action(action)
|
||||
|
||||
def handle_action(self, action: str):
|
||||
if isinstance(action, str):
|
||||
action_str = f' [yellow]{action.upper()}[/] '
|
||||
|
||||
if action == 'single':
|
||||
self.log(action_str.center(80, '='))
|
||||
state = self.get_state(self.args['ref_entity'])
|
||||
kwargs = {'kwargs': {'cause': f'button single click: toggle while {state}'}}
|
||||
if state == 'on':
|
||||
|
||||
26
console.py
26
console.py
@@ -4,17 +4,24 @@ import re
|
||||
from appdaemon.adapi import ADAPI
|
||||
from appdaemon.logging import AppNameFormatter
|
||||
from rich.console import Console
|
||||
from rich.highlighter import NullHighlighter
|
||||
from rich.highlighter import NullHighlighter, RegexHighlighter
|
||||
from rich.logging import RichHandler
|
||||
from rich.theme import Theme
|
||||
|
||||
|
||||
console = Console(
|
||||
width=150,
|
||||
theme=Theme({
|
||||
# 'appname': 'italic bright_cyan',
|
||||
'log.time': 'none',
|
||||
'logging.level.info': 'none',
|
||||
|
||||
'room': 'italic bright_cyan',
|
||||
'component': 'violet'
|
||||
'component': 'dark_violet',
|
||||
|
||||
'entity_id': 'light_slate_blue',
|
||||
'time': 'yellow',
|
||||
|
||||
'z2m': 'bright_black',
|
||||
'topic': 'chartreuse2',
|
||||
}),
|
||||
log_time_format='%Y-%m-%d %I:%M:%S %p',
|
||||
)
|
||||
@@ -54,10 +61,19 @@ class RoomControllerFormatter(logging.Formatter):
|
||||
return super().format(record)
|
||||
|
||||
|
||||
class RCHighlighter(RegexHighlighter):
|
||||
highlights = [
|
||||
r"(?P<entity_id>(light|switch)\.\w+)",
|
||||
r'(?P<time>\d+:\d+:\d+)',
|
||||
r'(?P<z2m>zigbee2mqtt/)'
|
||||
]
|
||||
|
||||
|
||||
def new_handler() -> RichHandler:
|
||||
return RichHandler(
|
||||
console=console,
|
||||
highlighter=NullHighlighter(),
|
||||
# highlighter=NullHighlighter(),
|
||||
highlighter=RCHighlighter(),
|
||||
markup=True,
|
||||
show_path=False,
|
||||
omit_repeated_times=False,
|
||||
|
||||
Reference in New Issue
Block a user