From 6e41320e0f49e05b8dc3de97a811c2a0368cb1b1 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Thu, 12 Dec 2024 16:44:22 -0700 Subject: [PATCH] fix(openhab): Fix rejectattr argument in `event` value_template Jinjava (the Jinja implementation openHAB uses) has an issue with a string as the third parameter to `rejectattr` (see HubSpot/jinjava#1227). Passing a tuple works around the issue, and is still compatible with Home Assistant's reference Python implementation. --- lib/extension/homeassistant.ts | 2 +- test/extensions/homeassistant.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts index b65f797f0d..9a95774b2b 100644 --- a/lib/extension/homeassistant.ts +++ b/lib/extension/homeassistant.ts @@ -2106,7 +2106,7 @@ export default class HomeAssistant extends Extension { ` {% set ns.r = ns.r|rejectattr(0, 'eq', 'action')|list + [('action', ns.r|selectattr(0, 'eq', 'actionPrefix')|map(attribute=1)|first + ns.r|selectattr(0, 'eq', 'action')|map(attribute=1)|first)] %}\n` + `{% endif %}\n` + `{% set ns.r = ns.r + [('event_type', ns.r|selectattr(0, 'eq', 'action')|map(attribute=1)|first)] %}\n` + - `{{dict.from_keys(ns.r|rejectattr(0, 'in', 'action, actionPrefix')|reject('eq', ('event_type', None))|reject('eq', ('event_type', '')))|to_json}}`; + `{{dict.from_keys(ns.r|rejectattr(0, 'in', ('action', 'actionPrefix'))|reject('eq', ('event_type', None))|reject('eq', ('event_type', '')))|to_json}}`; return value_template; } diff --git a/test/extensions/homeassistant.test.ts b/test/extensions/homeassistant.test.ts index 3fe4bdf388..cd831fbfbc 100644 --- a/test/extensions/homeassistant.test.ts +++ b/test/extensions/homeassistant.test.ts @@ -410,7 +410,7 @@ describe('Extension: HomeAssistant', () => { unique_id: '0x0017880104e45520_action_zigbee2mqtt', // Needs to be updated whenever one of the ACTION_*_PATTERN constants changes. value_template: - "{% set patterns = [\n{\"pattern\": '^(?P