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"> <div class="info">
<span class="value" <span class="value"
>${"attribute" in this._config >${"attribute" in this._config
? stateObj.attributes[this._config.attribute!] !== undefined
? formatAttributeValue( ? formatAttributeValue(
this.hass, this.hass,
stateObj.attributes[this._config.attribute!] ?? stateObj.attributes[this._config.attribute!]
this.hass.localize("state.default.unknown")
) )
: this.hass.localize("state.default.unknown")
: stateObj.attributes.unit_of_measurement : stateObj.attributes.unit_of_measurement
? formatNumber(stateObj.state, this.hass.locale) ? formatNumber(stateObj.state, this.hass.locale)
: computeStateDisplay( : computeStateDisplay(