From f55e911313e7866e26469926e250c84ec5239531 Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Wed, 26 May 2021 00:08:41 +0200 Subject: [PATCH] Prevent formatting for unknown attribute (#9252) --- src/panels/lovelace/cards/hui-entity-card.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/panels/lovelace/cards/hui-entity-card.ts b/src/panels/lovelace/cards/hui-entity-card.ts index 28c7709926..5c46621b55 100644 --- a/src/panels/lovelace/cards/hui-entity-card.ts +++ b/src/panels/lovelace/cards/hui-entity-card.ts @@ -125,11 +125,12 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
${"attribute" in this._config - ? formatAttributeValue( - this.hass, - stateObj.attributes[this._config.attribute!] ?? - this.hass.localize("state.default.unknown") - ) + ? stateObj.attributes[this._config.attribute!] !== undefined + ? formatAttributeValue( + this.hass, + stateObj.attributes[this._config.attribute!] + ) + : this.hass.localize("state.default.unknown") : stateObj.attributes.unit_of_measurement ? formatNumber(stateObj.state, this.hass.locale) : computeStateDisplay(