fixed default off_duration
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user