1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-19 18:28:42 +00:00

Avoid duplicate sensor readings by tracking devices contributing values

This commit is contained in:
Petar Petrov
2025-12-15 12:03:12 +02:00
parent d6d0da7ba1
commit 34f3550a6f

View File

@@ -394,6 +394,10 @@ export class HuiAreaCard extends LitElement implements LovelaceCard {
const values: number[] = [];
let uom: string | undefined;
// Track devices that have sensor entities contributing values
// to avoid duplicate readings from climate/humidifier attributes
const devicesWithSensorValues = new Set<string>();
for (const entityId of sensorEntityIds) {
const stateObj = this.hass.states[entityId];
if (
@@ -407,6 +411,11 @@ export class HuiAreaCard extends LitElement implements LovelaceCard {
}
if (stateObj.attributes.unit_of_measurement === uom) {
values.push(Number(stateObj.state));
// Track the device this sensor belongs to
const entityEntry = this.hass.entities[entityId];
if (entityEntry?.device_id) {
devicesWithSensorValues.add(entityEntry.device_id);
}
}
}
}
@@ -426,6 +435,15 @@ export class HuiAreaCard extends LitElement implements LovelaceCard {
const stateObj = this.hass.states[entityId];
if (!stateObj) continue;
// Skip if this entity's device already has a sensor contributing values
const entityEntry = this.hass.entities[entityId];
if (
entityEntry?.device_id &&
devicesWithSensorValues.has(entityEntry.device_id)
) {
continue;
}
const domain = entityId.split(".")[0];
const source = attrSources.find((s) => s.domain === domain);
if (!source) continue;