From d7dd11ba7f941235f1fe6b7c2881d6c23d62b646 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 1 May 2025 20:06:42 +0300 Subject: [PATCH] Improve error handling in automation i18n (#25266) --- .../entity/ha-entity-attribute-picker.ts | 16 +- src/data/automation_i18n.ts | 167 ++++++++++-------- 2 files changed, 103 insertions(+), 80 deletions(-) diff --git a/src/components/entity/ha-entity-attribute-picker.ts b/src/components/entity/ha-entity-attribute-picker.ts index 2468f6fe71..7e08060e33 100644 --- a/src/components/entity/ha-entity-attribute-picker.ts +++ b/src/components/entity/ha-entity-attribute-picker.ts @@ -73,16 +73,20 @@ class HaEntityAttributePicker extends LitElement { return nothing; } + const stateObj = this.hass.states[this.entityId!] as HassEntity | undefined; + return html` @@ -988,12 +1003,14 @@ const tryDescribeCondition = ( ); const attribute = condition.attribute - ? computeAttributeNameDisplay( - hass.localize, - stateObj, - hass.entities, - condition.attribute - ) + ? stateObj + ? computeAttributeNameDisplay( + hass.localize, + stateObj, + hass.entities, + condition.attribute + ) + : condition.attribute : undefined; if (condition.above !== undefined && condition.below !== undefined) { @@ -1187,7 +1204,9 @@ const tryDescribeCondition = ( if (localized) { return localized; } - const stateObj = hass.states[config.entity_id as string]; + const stateObj = hass.states[config.entity_id as string] as + | HassEntity + | undefined; return `${stateObj ? computeStateName(stateObj) : config.entity_id} ${ config.type }`;