Don't show duplicates in statistics picker (#19422)

* Filter duplicates from ha-statistics-picker

* use repeat
This commit is contained in:
karwosts 2024-01-16 13:40:27 -08:00 committed by GitHub
parent a06c9d0cc6
commit 22625a805d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View File

@ -129,7 +129,8 @@ export class HaStatisticPicker extends LitElement {
includeUnitClass?: string | string[],
includeDeviceClass?: string | string[],
entitiesOnly?: boolean,
excludeStatistics?: string[]
excludeStatistics?: string[],
value?: string
): StatisticItem[] => {
if (!statisticIds.length) {
return [
@ -176,6 +177,7 @@ export class HaStatisticPicker extends LitElement {
statisticIds.forEach((meta) => {
if (
excludeStatistics &&
meta.statistic_id !== value &&
excludeStatistics.includes(meta.statistic_id)
) {
return;
@ -258,7 +260,8 @@ export class HaStatisticPicker extends LitElement {
this.includeUnitClass,
this.includeDeviceClass,
this.entitiesOnly,
this.excludeStatistics
this.excludeStatistics,
this.value
);
} else {
this.updateComplete.then(() => {
@ -268,7 +271,8 @@ export class HaStatisticPicker extends LitElement {
this.includeUnitClass,
this.includeDeviceClass,
this.entitiesOnly,
this.excludeStatistics
this.excludeStatistics,
this.value
);
});
}

View File

@ -1,5 +1,6 @@
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
import { fireEvent } from "../../common/dom/fire_event";
import type { ValueChangedEvent, HomeAssistant } from "../../types";
import "./ha-statistic-picker";
@ -81,7 +82,9 @@ class HaStatisticsPicker extends LitElement {
: this.statisticTypes;
return html`
${this._currentStatistics.map(
${repeat(
this._currentStatistics,
(statisticId) => statisticId,
(statisticId) => html`
<div>
<ha-statistic-picker
@ -94,6 +97,7 @@ class HaStatisticsPicker extends LitElement {
.statisticTypes=${includeStatisticTypesCurrent}
.statisticIds=${this.statisticIds}
.label=${this.pickedStatisticLabel}
.excludeStatistics=${this.value}
.allowCustomEntity=${this.allowCustomEntity}
@value-changed=${this._statisticChanged}
></ha-statistic-picker>
@ -110,6 +114,7 @@ class HaStatisticsPicker extends LitElement {
.statisticTypes=${this.statisticTypes}
.statisticIds=${this.statisticIds}
.label=${this.pickStatisticLabel}
.excludeStatistics=${this.value}
.allowCustomEntity=${this.allowCustomEntity}
@value-changed=${this._addStatistic}
></ha-statistic-picker>