diff --git a/src/components/entity/ha-statistic-picker.ts b/src/components/entity/ha-statistic-picker.ts index 05b78bb05c..6d83012117 100644 --- a/src/components/entity/ha-statistic-picker.ts +++ b/src/components/entity/ha-statistic-picker.ts @@ -51,6 +51,14 @@ export class HaStatisticPicker extends LitElement { @property({ type: Array, attribute: "include-unit-of-measurement" }) public includeUnitOfMeasurement?: string[]; + /** + * Show only statistics with these device classes. + * @type {Array} + * @attr include-device-classes + */ + @property({ type: Array, attribute: "include-device-classes" }) + public includeDeviceClasses?: string[]; + /** * Show only statistics on entities. * @type {Boolean} @@ -116,6 +124,7 @@ export class HaStatisticPicker extends LitElement { ( statisticIds: StatisticsMetaData[], includeUnitOfMeasurement?: string[], + includeDeviceClasses?: string[], entitiesOnly?: boolean ): Array<{ id: string; name: string; state?: HassEntity }> => { if (!statisticIds.length) { @@ -148,11 +157,18 @@ export class HaStatisticPicker extends LitElement { } return; } - output.push({ - id: meta.statistic_id, - name: computeStateName(entityState), - state: entityState, - }); + if ( + !includeDeviceClasses || + includeDeviceClasses.includes( + entityState!.attributes.device_class || "" + ) + ) { + output.push({ + id: meta.statistic_id, + name: computeStateName(entityState), + state: entityState, + }); + } }); if (!output.length) { @@ -203,6 +219,7 @@ export class HaStatisticPicker extends LitElement { (this.comboBox as any).items = this._getStatistics( this.statisticIds!, this.includeUnitOfMeasurement, + this.includeDeviceClasses, this.entitiesOnly ); } else { @@ -210,6 +227,7 @@ export class HaStatisticPicker extends LitElement { (this.comboBox as any).items = this._getStatistics( this.statisticIds!, this.includeUnitOfMeasurement, + this.includeDeviceClasses, this.entitiesOnly ); }); diff --git a/src/panels/config/energy/components/ha-energy-battery-settings.ts b/src/panels/config/energy/components/ha-energy-battery-settings.ts index d1360fd61d..bff3bd0b50 100644 --- a/src/panels/config/energy/components/ha-energy-battery-settings.ts +++ b/src/panels/config/energy/components/ha-energy-battery-settings.ts @@ -4,7 +4,6 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property } from "lit/decorators"; import { fireEvent } from "../../../../common/dom/fire_event"; import { computeStateName } from "../../../../common/entity/compute_state_name"; -import "../../../../components/entity/ha-statistic-picker"; import "../../../../components/ha-card"; import "../../../../components/ha-settings-row"; import { diff --git a/src/panels/config/energy/dialogs/dialog-energy-battery-settings.ts b/src/panels/config/energy/dialogs/dialog-energy-battery-settings.ts index 20eda2eead..629d185ddc 100644 --- a/src/panels/config/energy/dialogs/dialog-energy-battery-settings.ts +++ b/src/panels/config/energy/dialogs/dialog-energy-battery-settings.ts @@ -15,6 +15,7 @@ import "@material/mwc-button/mwc-button"; import "../../../../components/entity/ha-statistic-picker"; const energyUnits = ["kWh"]; +const energyDeviceClasses = ["energy"]; @customElement("dialog-energy-battery-settings") export class DialogEnergyBatterySettings @@ -65,6 +66,7 @@ export class DialogEnergyBatterySettings