From 8ddd9879f25caa165ba7e53b01fa9f67497f8c69 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 10 Dec 2023 17:56:47 +0100 Subject: [PATCH] [#340] Alarm model enhancements. - Allow initialization of alarm actions from `Procedure` objects too. - Force `state=WAITING` when an alarm is disabled. --- platypush/plugins/alarm/_model.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/platypush/plugins/alarm/_model.py b/platypush/plugins/alarm/_model.py index 9a536f6197..bb6e7c761a 100644 --- a/platypush/plugins/alarm/_model.py +++ b/platypush/plugins/alarm/_model.py @@ -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,8 +67,12 @@ class Alarm: self.state = AlarmState.UNKNOWN self.timer: Optional[threading.Timer] = None self.static = static - self.actions = Procedure.build( - name=name, _async=False, requests=actions or [], id=self.id + self.actions = ( + actions + if isinstance(actions, Procedure) + else Procedure.build( + name=name, _async=False, requests=actions or [], id=self.id + ) ) self._enabled = enabled @@ -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