From 03c167d6b7bcc07b11945fb7f99f15585af29fc1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 10 Dec 2023 20:58:13 +0100 Subject: [PATCH] [#340] Added `Alarm.is_cron` property. --- platypush/plugins/alarm/_model.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/platypush/plugins/alarm/_model.py b/platypush/plugins/alarm/_model.py index bb6e7c76..8ec2d5f3 100644 --- a/platypush/plugins/alarm/_model.py +++ b/platypush/plugins/alarm/_model.py @@ -99,6 +99,17 @@ class Alarm: return media + @property + def is_cron(self) -> bool: + if not isinstance(self.when, str): + return False + + try: + croniter.croniter(self.when, time.time()).get_next() + return True + except (AttributeError, croniter.CroniterBadCronError): + return False + def get_next(self) -> Optional[float]: now = time.time() t = 0 @@ -288,6 +299,7 @@ class Alarm: 'snooze_interval': self.snooze_interval, 'actions': self.actions.requests, 'static': self.static, + 'is_cron': self.is_cron, } @classmethod @@ -323,6 +335,7 @@ class Alarm: snooze_interval=self.snooze_interval, enabled=self.is_enabled(), static=self.static, + is_cron=self.is_cron, )