From af28cda9a5cfaa99943f49f3ebf5fbd2340c930f Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 19:29:28 -0600 Subject: [PATCH] logging improvements --- button.py | 9 ++++----- door.py | 5 +---- room_control.py | 12 ++++++------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/button.py b/button.py index cb79b99..68e0996 100644 --- a/button.py +++ b/button.py @@ -35,13 +35,12 @@ class Button(Mqtt): except KeyError as e: return else: - self.log(f'{button}: {action}') - await self.handle_action(action) + if action != '': + await self.handle_action(action) async def handle_action(self, action: str): - if action == '': - return - elif action == 'single': + if action == 'single': + self.log(f' {action.upper()} '.center(50, '=')) cause = 'button single click' state = await self.get_state(entity_id=self.args['ref_entity']) if state == 'on': diff --git a/door.py b/door.py index 8b7a76e..50ca1c1 100644 --- a/door.py +++ b/door.py @@ -4,8 +4,5 @@ from room_control import RoomController class Door(Hass): async def initialize(self): - await self.listen_state(self.door_open, entity_id=self.args['door'], new='on') - - async def door_open(self, entity, attribute, old, new, kwargs): app: RoomController = await self.get_app(self.args['app']) - await app.activate_all_off() + await self.listen_state(app.activate_all_off, entity_id=self.args['door'], new='on', cause='door open') diff --git a/room_control.py b/room_control.py index e403035..f679177 100755 --- a/room_control.py +++ b/room_control.py @@ -65,7 +65,7 @@ class RoomController(Hass, Mqtt): dt = str(state['time'])[:8] self.log(f'Scheduling transition at: {dt}') try: - await self.run_at(callback=self.activate_any_on, start=dt) + await self.run_at(callback=self.activate_any_on, start=dt, cause='scheduled transition') except ValueError: # happens when the callback time is in the past pass @@ -205,21 +205,21 @@ class RoomController(Hass, Mqtt): self.log(f'ERROR: unknown scene: {scene}') @utils.sync_wrapper - async def activate_all_off(self, *args, **kwargs): + async def activate_all_off(self, entity, attribute = None, old = None, new = None, kwargs = None): """Activate if all of the entities are off """ if self.all_off: - self.log(f'Activate all off kwargs: {kwargs}') - self.activate(*args, **kwargs) + # self.log(f'Activate all off args/kwargs: {kwargs}') + self.activate(**kwargs) else: self.log(f'Skipped activating - everything is not off') @utils.sync_wrapper - async def activate_any_on(self, *args, **kwargs): + async def activate_any_on(self, entity, attribute = None, old = None, new = None, kwargs = None): """Activate if any of the entities are on """ if self.any_on: - self.activate(*args, **kwargs) + self.activate(**kwargs) else: self.log(f'Skipped activating - everything is off')