From cf91e6a2a3698fa4bfaf45ccc7a18ec7859b7c3a Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Fri, 27 Dec 2024 14:29:02 +0100 Subject: [PATCH] Calendar trigger: Handle optional offset better (#23474) Calendar empty offset --- src/data/automation_i18n.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/data/automation_i18n.ts b/src/data/automation_i18n.ts index 616659e68217..1542d1c0008d 100644 --- a/src/data/automation_i18n.ts +++ b/src/data/automation_i18n.ts @@ -737,18 +737,22 @@ const tryDescribeTrigger = ( ? computeStateName(hass.states[trigger.entity_id]) : trigger.entity_id; - let offsetChoice = trigger.offset.startsWith("-") ? "before" : "after"; - let offset: string | string[] = trigger.offset.startsWith("-") - ? trigger.offset.substring(1).split(":") - : trigger.offset.split(":"); - const duration = { - hours: offset.length > 0 ? +offset[0] : 0, - minutes: offset.length > 1 ? +offset[1] : 0, - seconds: offset.length > 2 ? +offset[2] : 0, - }; - offset = formatDurationLong(hass.locale, duration); - if (offset === "") { - offsetChoice = "other"; + let offsetChoice: string = "other"; + let offset: string | string[] = ""; + if (trigger.offset) { + offsetChoice = trigger.offset.startsWith("-") ? "before" : "after"; + offset = trigger.offset.startsWith("-") + ? trigger.offset.substring(1).split(":") + : trigger.offset.split(":"); + const duration = { + hours: offset.length > 0 ? +offset[0] : 0, + minutes: offset.length > 1 ? +offset[1] : 0, + seconds: offset.length > 2 ? +offset[2] : 0, + }; + offset = formatDurationLong(hass.locale, duration); + if (offset === "") { + offsetChoice = "other"; + } } return hass.localize(