From 22625a805d843da6900decfe6bb3923c3f46e6be Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:40:27 -0800 Subject: [PATCH] Don't show duplicates in statistics picker (#19422) * Filter duplicates from ha-statistics-picker * use repeat --- src/components/entity/ha-statistic-picker.ts | 10 +++++++--- src/components/entity/ha-statistics-picker.ts | 7 ++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/entity/ha-statistic-picker.ts b/src/components/entity/ha-statistic-picker.ts index b2227ee7af..d86c3bf053 100644 --- a/src/components/entity/ha-statistic-picker.ts +++ b/src/components/entity/ha-statistic-picker.ts @@ -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 ); }); } diff --git a/src/components/entity/ha-statistics-picker.ts b/src/components/entity/ha-statistics-picker.ts index 7079e5a6d5..115335094f 100644 --- a/src/components/entity/ha-statistics-picker.ts +++ b/src/components/entity/ha-statistics-picker.ts @@ -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`
@@ -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} >