Only show entities in energy with energy device class (#10076)

This commit is contained in:
Bram Kragten
2021-09-28 02:56:56 +02:00
committed by GitHub
parent 21e14bd644
commit abc4816888
6 changed files with 32 additions and 6 deletions

View File

@@ -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
);
});