Fix "unavailable" state in Area card (#25063)

* fix "unavailable" state

* Show "-" for unavailable/undefined
This commit is contained in:
ildar170975 2025-05-31 10:45:58 +03:00 committed by GitHub
parent 11e4a9f056
commit a099e65a9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -384,7 +384,10 @@ export class HuiAreaCard
areaSensorEntityId = area.humidity_entity_id; areaSensorEntityId = area.humidity_entity_id;
break; break;
} }
const areaEntity = areaSensorEntityId const areaEntity =
areaSensorEntityId &&
this.hass.states[areaSensorEntityId] &&
!isUnavailableState(this.hass.states[areaSensorEntityId].state)
? this.hass.states[areaSensorEntityId] ? this.hass.states[areaSensorEntityId]
: undefined; : undefined;
if ( if (
@ -393,6 +396,10 @@ export class HuiAreaCard
(entity) => entity.attributes.device_class === deviceClass (entity) => entity.attributes.device_class === deviceClass
) )
) { ) {
let value = areaEntity
? this.hass.formatEntityState(areaEntity)
: this._average(domain, deviceClass);
if (!value) value = "—";
sensors.push(html` sensors.push(html`
<div class="sensor"> <div class="sensor">
<ha-domain-icon <ha-domain-icon
@ -400,9 +407,7 @@ export class HuiAreaCard
.domain=${domain} .domain=${domain}
.deviceClass=${deviceClass} .deviceClass=${deviceClass}
></ha-domain-icon> ></ha-domain-icon>
${areaEntity ${value}
? this.hass.formatEntityState(areaEntity)
: this._average(domain, deviceClass)}
</div> </div>
`); `);
} }