From dc90468c655dbb52d0c94750f3783cf6c71bd622 Mon Sep 17 00:00:00 2001 From: mineiwik <29404520+mineiwik@users.noreply.github.com> Date: Tue, 31 Oct 2023 17:19:00 +0000 Subject: [PATCH 1/2] add delay wildcard --- README.md | 2 +- custom_components/alarmo/automations.py | 4 ++++ custom_components/alarmo/frontend/src/data/actions.ts | 9 +++++++++ .../src/views/actions/notification-editor-card.ts | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c3feab..ed915c9 100644 --- a/README.md +++ b/README.md @@ -481,7 +481,7 @@ By adding the wildcard in a message (including the brackets) it will be automati | `{{bypassed_sensors}}` | List of sensors which are bypassed | *Bedroom window* | Armed | | `{{arm_mode}}` | Current arming mode. | *Armed Away* | Leave
Armed | | `{{changed_by}}` | User who's code has been entered. | *Niels* | Armed
Disarmed | - +| `{{delay}}` | Delay in seconds until armed or the alarm is triggered | *30* | Arming
Pending | ##### Actionable notifications This function adds buttons to a push message, that can be clicked to interact with Alarmo. diff --git a/custom_components/alarmo/automations.py b/custom_components/alarmo/automations.py index c4920f9..2f1411b 100755 --- a/custom_components/alarmo/automations.py +++ b/custom_components/alarmo/automations.py @@ -210,6 +210,10 @@ async def async_execute_automation(self, automation_id: str, alarm_entity: Alarm changed_by = alarm_entity.changed_by if alarm_entity.changed_by else "" service_data[ATTR_MESSAGE] = service_data[ATTR_MESSAGE].replace("{{changed_by}}", changed_by) + if "{{delay}}" in service_data[ATTR_MESSAGE]: + delay = alarm_entity.delay if alarm_entity.delay else "" + service_data[ATTR_MESSAGE] = service_data[ATTR_MESSAGE].replace("{{delay}}", delay) + domain, service = action[ATTR_SERVICE].split(".") await self.hass.async_create_task( diff --git a/custom_components/alarmo/frontend/src/data/actions.ts b/custom_components/alarmo/frontend/src/data/actions.ts index a278b4c..f19de25 100755 --- a/custom_components/alarmo/frontend/src/data/actions.ts +++ b/custom_components/alarmo/frontend/src/data/actions.ts @@ -355,6 +355,15 @@ export const getWildcardOptions = (event?: EAlarmEvent, alarmoConfig?: AlarmoCon value: '{{arm_mode}}', }, ]; + + if (!event || [EAlarmEvent.Arming, EAlarmEvent.Pending].includes(event)) + options = [ + ...options, + { + name: 'Delay', + value: '{{delay}}', + }, + ]; return options; }; diff --git a/custom_components/alarmo/frontend/src/views/actions/notification-editor-card.ts b/custom_components/alarmo/frontend/src/views/actions/notification-editor-card.ts index d0f1b08..e7bcb63 100755 --- a/custom_components/alarmo/frontend/src/views/actions/notification-editor-card.ts +++ b/custom_components/alarmo/frontend/src/views/actions/notification-editor-card.ts @@ -783,6 +783,7 @@ export class NotificationEditorCard extends LitElement { message = message.replace('{{bypassed_sensors}}', 'Some Bypassed Sensor'); message = message.replace(/{{arm_mode(\|[^}]+)?}}/, 'Armed away'); message = message.replace('{{changed_by}}', 'Some Example User'); + message = message.replace('{{delay}}', '30'); this.hass .callService(domain, service, { From abbf08385534c48383bfb9f7a58acc19199cde16 Mon Sep 17 00:00:00 2001 From: mineiwik <29404520+mineiwik@users.noreply.github.com> Date: Sat, 4 Nov 2023 11:14:12 +0000 Subject: [PATCH 2/2] cast int to str --- custom_components/alarmo/automations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/alarmo/automations.py b/custom_components/alarmo/automations.py index 2f1411b..9f63138 100755 --- a/custom_components/alarmo/automations.py +++ b/custom_components/alarmo/automations.py @@ -211,7 +211,7 @@ async def async_execute_automation(self, automation_id: str, alarm_entity: Alarm service_data[ATTR_MESSAGE] = service_data[ATTR_MESSAGE].replace("{{changed_by}}", changed_by) if "{{delay}}" in service_data[ATTR_MESSAGE]: - delay = alarm_entity.delay if alarm_entity.delay else "" + delay = str(alarm_entity.delay) if alarm_entity.delay else "" service_data[ATTR_MESSAGE] = service_data[ATTR_MESSAGE].replace("{{delay}}", delay) domain, service = action[ATTR_SERVICE].split(".")