diff --git a/button.py b/button.py index b59020d..e3fdbe7 100644 --- a/button.py +++ b/button.py @@ -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': diff --git a/console.py b/console.py index 8db61c2..c22e10d 100644 --- a/console.py +++ b/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(light|switch)\.\w+)", + r'(?P