Prevent formatting for unknown attribute (#9252)

This commit is contained in:
Philip Allgaier 2021-05-26 00:08:41 +02:00 committed by GitHub
parent 465a91dbf3
commit f55e911313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,11 +125,12 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
<div class="info">
<span class="value"
>${"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(