fixed default off_duration

This commit is contained in:
John Lancaster
2024-01-22 18:57:24 -06:00
parent 826e866a52
commit 1c1990b632

View File

@@ -61,7 +61,7 @@ class RoomState:
@dataclass @dataclass
class RoomConfig: class RoomConfig:
states: List[RoomState] states: List[RoomState]
off_duration: timedelta = field(default_factory=timedelta) off_duration: timedelta = None
def __post_init__(self): def __post_init__(self):
if isinstance(self.off_duration, str): if isinstance(self.off_duration, str):
@@ -69,14 +69,16 @@ class RoomConfig:
@classmethod @classmethod
def from_app_config(cls, app_cfg: Dict[str, Dict]): def from_app_config(cls, app_cfg: Dict[str, Dict]):
if 'class' in app_cfg: if 'off_duration' in app_cfg:
app_cfg.pop('class') kwargs = {'off_duration': app_cfg['off_duration']}
if 'module' in app_cfg: else:
app_cfg.pop('module') kwargs = {}
self = cls(states=[RoomState.from_json(s) for s in app_cfg['states']])
for state in self.states: self = cls(
if state.off_duration is None: states=[RoomState.from_json(s) for s in app_cfg['states']],
state.off_duration = self.off_duration **kwargs
)
return self return self
@classmethod @classmethod
@@ -117,6 +119,7 @@ class RoomConfig:
else: else:
return state.off_duration return state.off_duration
class RoomController(Hass, Mqtt): class RoomController(Hass, Mqtt):
"""Class for linking an light with a motion sensor. """Class for linking an light with a motion sensor.
@@ -280,6 +283,7 @@ class RoomController(Hass, Mqtt):
""" """
sleep_mode_active = await self.sleep_bool() sleep_mode_active = await self.sleep_bool()
if sleep_mode_active: if sleep_mode_active:
self.log(f'Sleeping mode active: {sleep_mode_active}')
return timedelta() return timedelta()
else: else:
now = now or (await self.get_now()).time() now = now or (await self.get_now()).time()