diff --git a/src/panels/lovelace/components/hui-entity-editor.ts b/src/panels/lovelace/components/hui-entity-editor.ts index 36a0415d4790..719ee263a721 100644 --- a/src/panels/lovelace/components/hui-entity-editor.ts +++ b/src/panels/lovelace/components/hui-entity-editor.ts @@ -39,29 +39,31 @@ export class HuiEntityEditor extends LitElement { private _renderItem(item: EntityConfig, index: number) { const stateObj = this.hass.states[item.entity]; - const useDeviceName = entityUseDeviceName( - stateObj, - this.hass.entities, - this.hass.devices - ); + const useDeviceName = + stateObj && + entityUseDeviceName(stateObj, this.hass.entities, this.hass.devices); const isRTL = computeRTL(this.hass); const primary = + (stateObj && + this.hass.formatEntityName( + stateObj, + useDeviceName ? { type: "device" } : { type: "entity" } + )) || + item.entity; + + const secondary = + stateObj && this.hass.formatEntityName( stateObj, - useDeviceName ? { type: "device" } : { type: "entity" } - ) || item.entity; - - const secondary = this.hass.formatEntityName( - stateObj, - useDeviceName - ? [{ type: "area" }] - : [{ type: "area" }, { type: "device" }], - { - separator: isRTL ? " ◂ " : " ▸ ", - } - ); + useDeviceName + ? [{ type: "area" }] + : [{ type: "area" }, { type: "device" }], + { + separator: isRTL ? " ◂ " : " ▸ ", + } + ); return html`