From c11dbd2015b231253e8105959e13880b39b47627 Mon Sep 17 00:00:00 2001 From: mundschenk_at Date: Sat, 30 Nov 2024 13:21:50 +0100 Subject: [PATCH 1/2] fix(ignore): prevent empty events --- lib/extension/homeassistant.ts | 4 ++-- test/homeassistant.test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts index f5bfe1e234..c6e0f8c75b 100644 --- a/lib/extension/homeassistant.ts +++ b/lib/extension/homeassistant.ts @@ -2270,7 +2270,7 @@ export default class HomeAssistant extends Extension { const value_template = `{% set patterns = [\n${patterns}\n] %}\n` + - `{% set action_value = value_json.action|default(None) %}\n` + + `{% set action_value = value_json.action|default('') %}\n` + `{% set ns = namespace(r=[('action', action_value)]) %}\n` + `{% for p in patterns %}\n` + ` {% set m = action_value|regex_findall(p.pattern) %}\n` + @@ -2283,7 +2283,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'))|to_json}}`; + `{{dict.from_keys(ns.r|rejectattr(0, 'in', 'action, actionPrefix')|reject('eq', ('event_type', '')))|to_json}}`; return value_template; } diff --git a/test/homeassistant.test.js b/test/homeassistant.test.js index bee5fb819e..715a3de58e 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