logging improvements
This commit is contained in:
@@ -35,13 +35,12 @@ class Button(Mqtt):
|
|||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.log(f'{button}: {action}')
|
if action != '':
|
||||||
await self.handle_action(action)
|
await self.handle_action(action)
|
||||||
|
|
||||||
async def handle_action(self, action: str):
|
async def handle_action(self, action: str):
|
||||||
if action == '':
|
if action == 'single':
|
||||||
return
|
self.log(f' {action.upper()} '.center(50, '='))
|
||||||
elif action == 'single':
|
|
||||||
cause = 'button single click'
|
cause = 'button single click'
|
||||||
state = await self.get_state(entity_id=self.args['ref_entity'])
|
state = await self.get_state(entity_id=self.args['ref_entity'])
|
||||||
if state == 'on':
|
if state == 'on':
|
||||||
|
|||||||
5
door.py
5
door.py
@@ -4,8 +4,5 @@ from room_control import RoomController
|
|||||||
|
|
||||||
class Door(Hass):
|
class Door(Hass):
|
||||||
async def initialize(self):
|
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'])
|
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]
|
dt = str(state['time'])[:8]
|
||||||
self.log(f'Scheduling transition at: {dt}')
|
self.log(f'Scheduling transition at: {dt}')
|
||||||
try:
|
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:
|
except ValueError:
|
||||||
# happens when the callback time is in the past
|
# happens when the callback time is in the past
|
||||||
pass
|
pass
|
||||||
@@ -205,21 +205,21 @@ class RoomController(Hass, Mqtt):
|
|||||||
self.log(f'ERROR: unknown scene: {scene}')
|
self.log(f'ERROR: unknown scene: {scene}')
|
||||||
|
|
||||||
@utils.sync_wrapper
|
@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
|
"""Activate if all of the entities are off
|
||||||
"""
|
"""
|
||||||
if self.all_off:
|
if self.all_off:
|
||||||
self.log(f'Activate all off kwargs: {kwargs}')
|
# self.log(f'Activate all off args/kwargs: {kwargs}')
|
||||||
self.activate(*args, **kwargs)
|
self.activate(**kwargs)
|
||||||
else:
|
else:
|
||||||
self.log(f'Skipped activating - everything is not off')
|
self.log(f'Skipped activating - everything is not off')
|
||||||
|
|
||||||
@utils.sync_wrapper
|
@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
|
"""Activate if any of the entities are on
|
||||||
"""
|
"""
|
||||||
if self.any_on:
|
if self.any_on:
|
||||||
self.activate(*args, **kwargs)
|
self.activate(**kwargs)
|
||||||
else:
|
else:
|
||||||
self.log(f'Skipped activating - everything is off')
|
self.log(f'Skipped activating - everything is off')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user