From e617a9fe82720a3b66581ecf72be328358fa200f Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 18 Dec 2023 00:05:34 +0100 Subject: [PATCH] [alarm] Added `alarm.delete`. --- platypush/plugins/alarm/__init__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/platypush/plugins/alarm/__init__.py b/platypush/plugins/alarm/__init__.py index 280dea6422..7aaa66f07e 100644 --- a/platypush/plugins/alarm/__init__.py +++ b/platypush/plugins/alarm/__init__.py @@ -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): """