Skip to content

Commit

Permalink
Merge pull request #834 from mineiwik/main
Browse files Browse the repository at this point in the history
Add `delay` wildcard option
  • Loading branch information
nielsfaber authored Nov 7, 2023
2 parents 5bf3d18 + abbf083 commit a429707
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br> Armed |
| `{{changed_by}}` | User who's code has been entered. | *Niels* | Armed<br> Disarmed |

| `{{delay}}` | Delay in seconds until armed or the alarm is triggered | *30* | Arming<br> Pending |

##### Actionable notifications
This function adds buttons to a push message, that can be clicked to interact with Alarmo.
Expand Down
4 changes: 4 additions & 0 deletions custom_components/alarmo/automations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 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(".")

await self.hass.async_create_task(
Expand Down
9 changes: 9 additions & 0 deletions custom_components/alarmo/frontend/src/data/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit a429707

Please sign in to comment.