From d233ad7d57cff6d121c609dbf874f3e5f37ccbc7 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Mon, 9 Dec 2024 10:47:21 -0700 Subject: [PATCH] fix(openhab): fix syntax error in `event` value_template Jinjava (the Jinja implementation openHAB uses) has an issue with using `is defined` on a filter (see https://github.com/HubSpot/jinjava/issues/1226). Using parentheses works around the issue, and is still compatible with Home Assistant's reference Python implementation. --- lib/extension/homeassistant.ts | 2 +- test/homeassistant.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts index 63c085aefe..02130c6930 100644 --- a/lib/extension/homeassistant.ts +++ b/lib/extension/homeassistant.ts @@ -2279,7 +2279,7 @@ export default class HomeAssistant extends Extension { ` {% set ns.r = ns.r|rejectattr(0, 'eq', key)|list + [(key, value)] %}\n` + ` {% endfor %}\n` + `{% endfor %}\n` + - `{% if ns.r|selectattr(0, 'eq', 'actionPrefix')|first is defined %}\n` + + `{% if (ns.r|selectattr(0, 'eq', 'actionPrefix')|first) is defined %}\n` + ` {% 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` + diff --git a/test/homeassistant.test.js b/test/homeassistant.test.js index 8475290db8..55e7713e02 100644 --- a/test/homeassistant.test.js +++ b/test/homeassistant.test.js @@ -428,7 +428,7 @@ describe('HomeAssistant extension', () => { unique_id: '0x0017880104e45520_action_zigbee2mqtt', // Needs to be updated whenever one of the ACTION_*_PATTERN constants changes. value_template: - "{% set patterns = [\n{\"pattern\": '^(?P