Preserve custom names in statistics graph when modifying entity list (#15695)

This commit is contained in:
karwosts 2023-03-06 08:10:08 -08:00 committed by GitHub
parent 4d19e3ad63
commit 55edeb474e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -300,18 +300,26 @@ export class HuiStatisticsGraphCardEditor
}
private async _entitiesChanged(ev: CustomEvent): Promise<void> {
const config = { ...this._config!, entities: ev.detail.value };
const newEntityIds = ev.detail.value;
// Save the EntityConfig objects from being replaced with strings
const newEntities = newEntityIds.map((newEnt) => {
const matchEntity = this._config!.entities.find(
(oldEnt) => typeof oldEnt !== "string" && oldEnt.entity === newEnt
);
return matchEntity ?? newEnt;
});
const config = { ...this._config!, entities: newEntities };
if (
config.entities?.some((statistic_id) =>
isExternalStatistic(statistic_id)
) &&
newEntityIds?.some((statistic_id) => isExternalStatistic(statistic_id)) &&
config.period === "5minute"
) {
delete config.period;
}
const metadata =
config.stat_types || config.unit
? await getStatisticMetadata(this.hass!, config.entities)
? await getStatisticMetadata(this.hass!, newEntityIds)
: undefined;
if (config.stat_types && config.entities.length) {
config.stat_types = ensureArray(config.stat_types).filter((stat_type) =>