From afc5e456425ae7c1ba1e64d05bcf8405edc67296 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 18:41:49 -0600 Subject: [PATCH] bug fix from scene detector --- motion.py | 2 ++ room_control.py | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/motion.py b/motion.py index a598164..7149283 100644 --- a/motion.py +++ b/motion.py @@ -73,6 +73,7 @@ class Motion(Hass): cause='motion off' ) + @utils.sync_wrapper async def callback_light_on(self, entity=None, attribute=None, old=None, new=None, kwargs=None): """Called when the light turns on """ @@ -81,6 +82,7 @@ class Motion(Hass): await self.cancel_motion_callback(new='on') 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): """Called when the light turns off """ diff --git a/room_control.py b/room_control.py index 21e48b1..e403035 100755 --- a/room_control.py +++ b/room_control.py @@ -1,6 +1,6 @@ import asyncio from copy import deepcopy -from datetime import time, timedelta +from datetime import datetime, time, timedelta from typing import List import appdaemon.utils as utils @@ -103,17 +103,18 @@ class RoomController(Hass, Mqtt): async def current_state(self, time: time = None): if (await self.sleep_bool()): + self.log(f'sleep: active') if (state := self.args.get('sleep_state')): return state else: return {} else: - now = await self.get_now() - self.log(f'Getting state for datetime: {now}') + now: datetime = await self.get_now() + self.log(f'Getting state for datetime: {now.strftime("%I:%M:%S %p")}') time = time or (await self.get_now()).time() for state in self.states[::-1]: 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 else: return self.states[-1] @@ -178,6 +179,7 @@ class RoomController(Hass, Mqtt): except Exception: return timedelta() + @utils.sync_wrapper async def activate(self, *args, cause: str = 'unknown', **kwargs): self.log(f'Activating: {cause}') scene = await self.current_scene() @@ -202,20 +204,22 @@ class RoomController(Hass, Mqtt): else: self.log(f'ERROR: unknown scene: {scene}') + @utils.sync_wrapper async def activate_all_off(self, *args, **kwargs): """Activate if all of the entities are off """ if self.all_off: self.log(f'Activate all off kwargs: {kwargs}') - await self.activate(*args, **kwargs) + self.activate(*args, **kwargs) else: self.log(f'Skipped activating - everything is not off') + @utils.sync_wrapper async def activate_any_on(self, *args, **kwargs): """Activate if any of the entities are on """ if self.any_on: - await self.activate(*args, **kwargs) + self.activate(*args, **kwargs) else: self.log(f'Skipped activating - everything is off')