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