Use entity format state if only one entity for that domain in the area card (#25964)

Use entity format state if only one entity is area card
This commit is contained in:
Paul Bottein 2025-06-27 17:41:58 +02:00
parent 5430325127
commit 6f753c4909
No known key found for this signature in database

View File

@ -348,6 +348,14 @@ export class HuiAreaCard extends LitElement implements LovelaceCard {
return undefined;
}
// If only one entity, return its formatted state
if (entities.length === 1) {
const stateObj = entities[0];
return isUnavailableState(stateObj.state)
? ""
: this.hass.formatEntityState(stateObj);
}
// Use the first entity's unit_of_measurement for formatting
const uom = entities.find(
(entity) => entity.attributes.unit_of_measurement