forked from platypush/platypush
[#340] Added Alarm.is_cron
property.
This commit is contained in:
parent
2d8f6102c1
commit
03c167d6b7
1 changed files with 13 additions and 0 deletions
|
@ -99,6 +99,17 @@ class Alarm:
|
||||||
|
|
||||||
return media
|
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]:
|
def get_next(self) -> Optional[float]:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
t = 0
|
t = 0
|
||||||
|
@ -288,6 +299,7 @@ class Alarm:
|
||||||
'snooze_interval': self.snooze_interval,
|
'snooze_interval': self.snooze_interval,
|
||||||
'actions': self.actions.requests,
|
'actions': self.actions.requests,
|
||||||
'static': self.static,
|
'static': self.static,
|
||||||
|
'is_cron': self.is_cron,
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -323,6 +335,7 @@ class Alarm:
|
||||||
snooze_interval=self.snooze_interval,
|
snooze_interval=self.snooze_interval,
|
||||||
enabled=self.is_enabled(),
|
enabled=self.is_enabled(),
|
||||||
static=self.static,
|
static=self.static,
|
||||||
|
is_cron=self.is_cron,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue