Skip to content

Commit

Permalink
Don't show duplicates in statistics picker (#19422)
Browse files Browse the repository at this point in the history
* Filter duplicates from ha-statistics-picker

* use repeat
  • Loading branch information
karwosts authored Jan 16, 2024
1 parent a06c9d0 commit 22625a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/components/entity/ha-statistic-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -176,6 +177,7 @@ export class HaStatisticPicker extends LitElement {
statisticIds.forEach((meta) => {
if (
excludeStatistics &&
meta.statistic_id !== value &&
excludeStatistics.includes(meta.statistic_id)
) {
return;
Expand Down Expand Up @@ -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(() => {
Expand All @@ -268,7 +271,8 @@ export class HaStatisticPicker extends LitElement {
this.includeUnitClass,
this.includeDeviceClass,
this.entitiesOnly,
this.excludeStatistics
this.excludeStatistics,
this.value
);
});
}
Expand Down
7 changes: 6 additions & 1 deletion src/components/entity/ha-statistics-picker.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit 22625a8

Please sign in to comment.