greatly improved from implementing the "logging endgame" notebook
This commit is contained in:
@@ -7,7 +7,7 @@ from typing import Dict, List
|
||||
from appdaemon.entity import Entity
|
||||
from appdaemon.plugins.hass.hassapi import Hass
|
||||
from appdaemon.plugins.mqtt.mqttapi import Mqtt
|
||||
from console import console, create_rich_logging_dict
|
||||
from console import console, room_logging_config
|
||||
from model import ControllerStateConfig, RoomControllerConfig
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -32,11 +32,14 @@ class RoomController(Hass, Mqtt):
|
||||
assert all(isinstance(s, ControllerStateConfig) for s in new), f'Invalid: {new}'
|
||||
self._room_config.states = new
|
||||
|
||||
def initialize(self):
|
||||
cfg_dict = create_rich_logging_dict(parent_room=self.name)
|
||||
logging.config.dictConfig(cfg_dict)
|
||||
self.logger = logging.getLogger(next(iter(cfg_dict['loggers'])))
|
||||
def configure_logging(self) -> dict:
|
||||
logging.config.dictConfig(room_logging_config(self.name))
|
||||
self.logger = logging.LoggerAdapter(
|
||||
logging.getLogger(f'AppDaemon.{self.name}'), {'room': self.name}
|
||||
)
|
||||
|
||||
def initialize(self):
|
||||
self.configure_logging()
|
||||
self.app_entities = self.gather_app_entities()
|
||||
# self.log(f'entities: {self.app_entities}')
|
||||
self.refresh_state_times()
|
||||
@@ -88,9 +91,9 @@ class RoomController(Hass, Mqtt):
|
||||
|
||||
assert isinstance(state.time, datetime.time), f'Invalid time: {state.time}'
|
||||
|
||||
if self.logger.isEnabledFor(logging.DEBUG):
|
||||
# table = self._room_config.rich_table(self.name)
|
||||
console.print(self._room_config)
|
||||
# if self.logger.isEnabledFor(logging.DEBUG):
|
||||
# # table = self._room_config.rich_table(self.name)
|
||||
# console.print(self._room_config)
|
||||
|
||||
self.states = sorted(self.states, key=lambda s: s.time, reverse=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user