logging improvements
This commit is contained in:
@@ -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':
|
||||
|
||||
5
door.py
5
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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user