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): """