forked from platypush/platypush
[#340] Alarm model enhancements.
- Allow initialization of alarm actions from `Procedure` objects too. - Force `state=WAITING` when an alarm is disabled.
This commit is contained in:
parent
686085750f
commit
8ddd9879f2
1 changed files with 10 additions and 3 deletions
|
@ -44,7 +44,7 @@ class Alarm:
|
|||
def __init__(
|
||||
self,
|
||||
when: Union[str, int, float],
|
||||
actions: Optional[list] = None,
|
||||
actions: Optional[Union[list, Procedure]] = None,
|
||||
name: Optional[str] = None,
|
||||
media: Optional[str] = None,
|
||||
media_plugin: Optional[str] = None,
|
||||
|
@ -67,9 +67,13 @@ class Alarm:
|
|||
self.state = AlarmState.UNKNOWN
|
||||
self.timer: Optional[threading.Timer] = None
|
||||
self.static = static
|
||||
self.actions = Procedure.build(
|
||||
self.actions = (
|
||||
actions
|
||||
if isinstance(actions, Procedure)
|
||||
else Procedure.build(
|
||||
name=name, _async=False, requests=actions or [], id=self.id
|
||||
)
|
||||
)
|
||||
|
||||
self._enabled = enabled
|
||||
self._runtime_snooze_interval = snooze_interval
|
||||
|
@ -219,6 +223,9 @@ class Alarm:
|
|||
self.play_audio()
|
||||
|
||||
self.actions.execute()
|
||||
elif self.state != AlarmState.WAITING:
|
||||
self.state = AlarmState.WAITING
|
||||
self._on_change()
|
||||
|
||||
self.wait_stop(self.poll_interval)
|
||||
sleep_time = None
|
||||
|
|
Loading…
Reference in a new issue