moved off_duration back
This commit is contained in:
20
motion.py
20
motion.py
@@ -16,30 +16,14 @@ class Motion(Hass):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def off_duration(self) -> timedelta:
|
def off_duration(self) -> timedelta:
|
||||||
"""Determines the time that the motion sensor has to be clear before deactivating
|
return self.app.off_duration
|
||||||
|
|
||||||
Priority:
|
|
||||||
- Value in scene definition
|
|
||||||
- Default value
|
|
||||||
- Normal - value in app definition
|
|
||||||
- Sleep - 0
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
duration_str = self.args.get('off_duration', '00:00:00')
|
|
||||||
|
|
||||||
try:
|
|
||||||
hours, minutes, seconds = map(int, duration_str.split(':'))
|
|
||||||
return timedelta(hours=hours, minutes=minutes, seconds=seconds)
|
|
||||||
except Exception:
|
|
||||||
return timedelta()
|
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
self.app: RoomController = self.get_app(self.args['app'])
|
self.app: RoomController = self.get_app(self.args['app'])
|
||||||
self.log(f'Connected to app {self.app.name}')
|
self.log(f'Connected to app {self.app.name}')
|
||||||
|
|
||||||
self.listen_state(self.callback_light_on, self.args['entity'], new='on')
|
self.listen_state(self.callback_light_on, self.args['entity'], new='on')
|
||||||
self.listen_state(self.callback_light_on, self.args['entity'], new='off')
|
self.listen_state(self.callback_light_off, self.args['entity'], new='off')
|
||||||
|
|
||||||
self.listen_motion_on()
|
self.listen_motion_on()
|
||||||
self.listen_motion_off(self.off_duration)
|
self.listen_motion_off(self.off_duration)
|
||||||
|
|||||||
@@ -180,6 +180,29 @@ class RoomController(Hass, Mqtt):
|
|||||||
else:
|
else:
|
||||||
raise ValueError('Sleep variable is undefined')
|
raise ValueError('Sleep variable is undefined')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def off_duration(self) -> timedelta:
|
||||||
|
"""Determines the time that the motion sensor has to be clear before deactivating
|
||||||
|
|
||||||
|
Priority:
|
||||||
|
- Value in scene definition
|
||||||
|
- Default value
|
||||||
|
- Normal - value in app definition
|
||||||
|
- Sleep - 0
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
duration_str = self.current_state().get(
|
||||||
|
'off_duration',
|
||||||
|
self.args.get('off_duration', '00:00:00')
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
hours, minutes, seconds = map(int, duration_str.split(':'))
|
||||||
|
return timedelta(hours=hours, minutes=minutes, seconds=seconds)
|
||||||
|
except Exception:
|
||||||
|
return timedelta()
|
||||||
|
|
||||||
def activate(self, *args, cause: str = 'unknown', **kwargs):
|
def activate(self, *args, cause: str = 'unknown', **kwargs):
|
||||||
self.log(f'Activating: {cause}')
|
self.log(f'Activating: {cause}')
|
||||||
scene = self.current_scene()
|
scene = self.current_scene()
|
||||||
|
|||||||
Reference in New Issue
Block a user