[#340] Added `Alarm.is_cron` property.

This commit is contained in:
Fabio Manganiello 2023-12-10 20:58:13 +01:00
parent 2d8f6102c1
commit 03c167d6b7
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
1 changed files with 13 additions and 0 deletions

View File

@ -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,
)