forked from platypush/platypush
[alarm] Added alarm.delete
.
This commit is contained in:
parent
b7423e1c34
commit
e617a9fe82
1 changed files with 18 additions and 0 deletions
|
@ -412,6 +412,24 @@ class AlarmPlugin(RunnablePlugin, EntityManager):
|
||||||
snooze_interval=snooze_interval or alarm.snooze_interval,
|
snooze_interval=snooze_interval or alarm.snooze_interval,
|
||||||
).to_dict()
|
).to_dict()
|
||||||
|
|
||||||
|
@action
|
||||||
|
def delete(self, name: str):
|
||||||
|
"""
|
||||||
|
Delete an alarm.
|
||||||
|
|
||||||
|
:param name: Alarm name.
|
||||||
|
"""
|
||||||
|
alarm = self._get_alarm(name)
|
||||||
|
assert not alarm.static, (
|
||||||
|
f'Alarm {name} is statically defined in the configuration, '
|
||||||
|
'cannot overwrite it programmatically'
|
||||||
|
)
|
||||||
|
|
||||||
|
with self._db.get_session() as session:
|
||||||
|
db_alarm = session.query(DbAlarm).filter_by(name=name).first()
|
||||||
|
assert db_alarm, f'Alarm {name} does not exist'
|
||||||
|
self._clear_alarm(db_alarm, session)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def enable(self, name: str):
|
def enable(self, name: str):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue