Avoid duplicate entity ids in history (#20402)

* Avoid duplicate entity ids in history

* Don't need to check for size
This commit is contained in:
Paul Bottein 2024-04-04 12:12:04 +02:00 committed by GitHub
parent 5f5ac5419b
commit 3a4e9b6856
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -525,14 +525,12 @@ class HaPanelHistory extends LitElement {
} }
const targetSelector = { target: {} }; const targetSelector = { target: {} };
const targetEntities = const targetEntities = new Set(ensureArray(targetPickerValue.entity_id));
ensureArray(targetPickerValue.entity_id)?.slice() || []; const targetDevices = new Set(ensureArray(targetPickerValue.device_id));
const targetDevices = const targetAreas = new Set(ensureArray(targetPickerValue.area_id));
ensureArray(targetPickerValue.device_id)?.slice() || []; const targetFloors = new Set(ensureArray(targetPickerValue.floor_id));
const targetAreas = ensureArray(targetPickerValue.area_id)?.slice() || []; const targetLabels = new Set(ensureArray(targetPickerValue.label_id));
const targetFloors = ensureArray(targetPickerValue.floor_id)?.slice();
const targetLabels = ensureArray(targetPickerValue.label_id)?.slice();
if (targetLabels) {
targetLabels.forEach((labelId) => { targetLabels.forEach((labelId) => {
const expanded = expandLabelTarget( const expanded = expandLabelTarget(
this.hass, this.hass,
@ -542,12 +540,11 @@ class HaPanelHistory extends LitElement {
entities, entities,
targetSelector targetSelector
); );
targetDevices.push(...expanded.devices); expanded.devices.forEach((id) => targetDevices.add(id));
targetEntities.push(...expanded.entities); expanded.entities.forEach((id) => targetEntities.add(id));
targetAreas.push(...expanded.areas); expanded.areas.forEach((id) => targetAreas.add(id));
}); });
}
if (targetFloors) {
targetFloors.forEach((floorId) => { targetFloors.forEach((floorId) => {
const expanded = expandFloorTarget( const expanded = expandFloorTarget(
this.hass, this.hass,
@ -555,10 +552,9 @@ class HaPanelHistory extends LitElement {
areas, areas,
targetSelector targetSelector
); );
targetAreas.push(...expanded.areas); expanded.areas.forEach((id) => targetAreas.add(id));
}); });
}
if (targetAreas.length) {
targetAreas.forEach((areaId) => { targetAreas.forEach((areaId) => {
const expanded = expandAreaTarget( const expanded = expandAreaTarget(
this.hass, this.hass,
@ -567,20 +563,21 @@ class HaPanelHistory extends LitElement {
entities, entities,
targetSelector targetSelector
); );
targetEntities.push(...expanded.entities); expanded.devices.forEach((id) => targetDevices.add(id));
targetDevices.push(...expanded.devices); expanded.entities.forEach((id) => targetEntities.add(id));
}); });
}
if (targetDevices.length) {
targetDevices.forEach((deviceId) => {
targetEntities.push(
...expandDeviceTarget(this.hass, deviceId, entities, targetSelector)
.entities
);
});
}
return targetEntities; targetDevices.forEach((deviceId) => {
const expanded = expandDeviceTarget(
this.hass,
deviceId,
entities,
targetSelector
);
expanded.entities.forEach((id) => targetEntities.add(id));
});
return Array.from(targetEntities);
} }
); );