From 1c1990b632539fafeb3e8b164f89de6a1ad15b76 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:57:24 -0600 Subject: [PATCH] fixed default off_duration --- room_control.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/room_control.py b/room_control.py index a94cd5c..c00bd98 100755 --- a/room_control.py +++ b/room_control.py @@ -61,7 +61,7 @@ class RoomState: @dataclass class RoomConfig: states: List[RoomState] - off_duration: timedelta = field(default_factory=timedelta) + off_duration: timedelta = None def __post_init__(self): if isinstance(self.off_duration, str): @@ -69,14 +69,16 @@ class RoomConfig: @classmethod def from_app_config(cls, app_cfg: Dict[str, Dict]): - if 'class' in app_cfg: - app_cfg.pop('class') - if 'module' in app_cfg: - app_cfg.pop('module') - self = cls(states=[RoomState.from_json(s) for s in app_cfg['states']]) - for state in self.states: - if state.off_duration is None: - state.off_duration = self.off_duration + if 'off_duration' in app_cfg: + kwargs = {'off_duration': app_cfg['off_duration']} + else: + kwargs = {} + + self = cls( + states=[RoomState.from_json(s) for s in app_cfg['states']], + **kwargs + ) + return self @classmethod @@ -117,6 +119,7 @@ class RoomConfig: else: return state.off_duration + class RoomController(Hass, Mqtt): """Class for linking an light with a motion sensor. @@ -280,6 +283,7 @@ class RoomController(Hass, Mqtt): """ sleep_mode_active = await self.sleep_bool() if sleep_mode_active: + self.log(f'Sleeping mode active: {sleep_mode_active}') return timedelta() else: now = now or (await self.get_now()).time()