[alarm] Added `alarm.delete`.

This commit is contained in:
Fabio Manganiello 2023-12-18 00:05:34 +01:00
parent b7423e1c34
commit e617a9fe82
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
1 changed files with 18 additions and 0 deletions

View File

@ -412,6 +412,24 @@ class AlarmPlugin(RunnablePlugin, EntityManager):
snooze_interval=snooze_interval or alarm.snooze_interval,
).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
def enable(self, name: str):
"""