bug fix from scene detector

This commit is contained in:
John Lancaster
2023-11-25 18:41:49 -06:00
parent 8a5431a72b
commit afc5e45642
2 changed files with 12 additions and 6 deletions

View File

@@ -73,6 +73,7 @@ class Motion(Hass):
cause='motion off' cause='motion off'
) )
@utils.sync_wrapper
async def callback_light_on(self, entity=None, attribute=None, old=None, new=None, kwargs=None): async def callback_light_on(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
"""Called when the light turns on """Called when the light turns on
""" """
@@ -81,6 +82,7 @@ class Motion(Hass):
await self.cancel_motion_callback(new='on') await self.cancel_motion_callback(new='on')
self.listen_motion_off(await self.app.off_duration()) self.listen_motion_off(await self.app.off_duration())
@utils.sync_wrapper
async def callback_light_off(self, entity=None, attribute=None, old=None, new=None, kwargs=None): async def callback_light_off(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
"""Called when the light turns off """Called when the light turns off
""" """

View File

@@ -1,6 +1,6 @@
import asyncio import asyncio
from copy import deepcopy from copy import deepcopy
from datetime import time, timedelta from datetime import datetime, time, timedelta
from typing import List from typing import List
import appdaemon.utils as utils import appdaemon.utils as utils
@@ -103,17 +103,18 @@ class RoomController(Hass, Mqtt):
async def current_state(self, time: time = None): async def current_state(self, time: time = None):
if (await self.sleep_bool()): if (await self.sleep_bool()):
self.log(f'sleep: active')
if (state := self.args.get('sleep_state')): if (state := self.args.get('sleep_state')):
return state return state
else: else:
return {} return {}
else: else:
now = await self.get_now() now: datetime = await self.get_now()
self.log(f'Getting state for datetime: {now}') self.log(f'Getting state for datetime: {now.strftime("%I:%M:%S %p")}')
time = time or (await self.get_now()).time() time = time or (await self.get_now()).time()
for state in self.states[::-1]: for state in self.states[::-1]:
if state['time'] <= time: if state['time'] <= time:
self.log(f'Selected state from {state["time"]}') self.log(f'Selected state from {state["time"].strftime("%I:%M:%S %p")}')
return state return state
else: else:
return self.states[-1] return self.states[-1]
@@ -178,6 +179,7 @@ class RoomController(Hass, Mqtt):
except Exception: except Exception:
return timedelta() return timedelta()
@utils.sync_wrapper
async def activate(self, *args, cause: str = 'unknown', **kwargs): async def activate(self, *args, cause: str = 'unknown', **kwargs):
self.log(f'Activating: {cause}') self.log(f'Activating: {cause}')
scene = await self.current_scene() scene = await self.current_scene()
@@ -202,20 +204,22 @@ class RoomController(Hass, Mqtt):
else: else:
self.log(f'ERROR: unknown scene: {scene}') self.log(f'ERROR: unknown scene: {scene}')
@utils.sync_wrapper
async def activate_all_off(self, *args, **kwargs): async def activate_all_off(self, *args, **kwargs):
"""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 kwargs: {kwargs}')
await self.activate(*args, **kwargs) self.activate(*args, **kwargs)
else: else:
self.log(f'Skipped activating - everything is not off') 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, *args, **kwargs):
"""Activate if any of the entities are on """Activate if any of the entities are on
""" """
if self.any_on: if self.any_on:
await self.activate(*args, **kwargs) self.activate(*args, **kwargs)
else: else:
self.log(f'Skipped activating - everything is off') self.log(f'Skipped activating - everything is off')