mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 07:16:39 +00:00
Add support for external stats (#10411)
This commit is contained in:
parent
171eddd779
commit
bd1a9f2cb0
@ -102,7 +102,12 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
</style>
|
</style>
|
||||||
<ha-svg-icon .path=${mdiCheck}></ha-svg-icon>
|
<ha-svg-icon .path=${mdiCheck}></ha-svg-icon>
|
||||||
<paper-icon-item>
|
<paper-icon-item>
|
||||||
<state-badge slot="item-icon" .stateObj=${item.state}></state-badge>
|
${item.state
|
||||||
|
? html`<state-badge
|
||||||
|
slot="item-icon"
|
||||||
|
.stateObj=${item.state}
|
||||||
|
></state-badge>`
|
||||||
|
: ""}
|
||||||
<paper-item-body two-line="">
|
<paper-item-body two-line="">
|
||||||
${item.name}
|
${item.name}
|
||||||
<span secondary
|
<span secondary
|
||||||
@ -153,7 +158,10 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
const entityState = this.hass.states[meta.statistic_id];
|
const entityState = this.hass.states[meta.statistic_id];
|
||||||
if (!entityState) {
|
if (!entityState) {
|
||||||
if (!entitiesOnly) {
|
if (!entitiesOnly) {
|
||||||
output.push({ id: meta.statistic_id, name: meta.statistic_id });
|
output.push({
|
||||||
|
id: meta.statistic_id,
|
||||||
|
name: meta.name || meta.statistic_id,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,8 @@ export interface StatisticValue {
|
|||||||
export interface StatisticsMetaData {
|
export interface StatisticsMetaData {
|
||||||
unit_of_measurement: string;
|
unit_of_measurement: string;
|
||||||
statistic_id: string;
|
statistic_id: string;
|
||||||
|
source: string;
|
||||||
|
name?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type StatisticsValidationResult =
|
export type StatisticsValidationResult =
|
||||||
|
@ -73,7 +73,6 @@ export class DialogEnergyBatterySettings
|
|||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.energy.battery.dialog.energy_into_battery"
|
"ui.panel.config.energy.battery.dialog.energy_into_battery"
|
||||||
)}
|
)}
|
||||||
entities-only
|
|
||||||
@value-changed=${this._statisticToChanged}
|
@value-changed=${this._statisticToChanged}
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
|
||||||
@ -85,7 +84,6 @@ export class DialogEnergyBatterySettings
|
|||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.energy.battery.dialog.energy_out_of_battery"
|
"ui.panel.config.energy.battery.dialog.energy_out_of_battery"
|
||||||
)}
|
)}
|
||||||
entities-only
|
|
||||||
@value-changed=${this._statisticFromChanged}
|
@value-changed=${this._statisticFromChanged}
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
|
||||||
|
@ -74,7 +74,6 @@ export class DialogEnergyDeviceSettings
|
|||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.energy.device_consumption.dialog.device_consumption_energy"
|
"ui.panel.config.energy.device_consumption.dialog.device_consumption_energy"
|
||||||
)}
|
)}
|
||||||
entities-only
|
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
|
||||||
|
@ -106,7 +106,6 @@ export class DialogEnergyGasSettings
|
|||||||
? "kWh"
|
? "kWh"
|
||||||
: "m³"
|
: "m³"
|
||||||
})`}
|
})`}
|
||||||
entities-only
|
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
|
||||||
|
@ -103,7 +103,6 @@ export class DialogEnergyGridFlowSettings
|
|||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
`ui.panel.config.energy.grid.flow_dialog.${this._params.direction}.energy_stat`
|
`ui.panel.config.energy.grid.flow_dialog.${this._params.direction}.energy_stat`
|
||||||
)}
|
)}
|
||||||
entities-only
|
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
|
||||||
|
@ -85,7 +85,6 @@ export class DialogEnergySolarSettings
|
|||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.energy.solar.dialog.solar_production_energy"
|
"ui.panel.config.energy.solar.dialog.solar_production_energy"
|
||||||
)}
|
)}
|
||||||
entities-only
|
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
|
||||||
|
@ -50,21 +50,21 @@ class HaPanelDevStatistics extends LitElement {
|
|||||||
private _columns = memoizeOne(
|
private _columns = memoizeOne(
|
||||||
(localize): DataTableColumnContainer => ({
|
(localize): DataTableColumnContainer => ({
|
||||||
state: {
|
state: {
|
||||||
title: "Entity",
|
title: "Name",
|
||||||
sortable: true,
|
sortable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
grows: true,
|
grows: true,
|
||||||
template: (entityState, data: any) =>
|
template: (entityState, data: any) =>
|
||||||
html`${entityState
|
html`${entityState
|
||||||
? computeStateName(entityState)
|
? computeStateName(entityState)
|
||||||
: data.statistic_id}`,
|
: data.name || data.statistic_id}`,
|
||||||
},
|
},
|
||||||
statistic_id: {
|
statistic_id: {
|
||||||
title: "Statistic id",
|
title: "Statistic id",
|
||||||
sortable: true,
|
sortable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
hidden: this.narrow,
|
hidden: this.narrow,
|
||||||
width: "30%",
|
width: "20%",
|
||||||
},
|
},
|
||||||
unit_of_measurement: {
|
unit_of_measurement: {
|
||||||
title: "Unit",
|
title: "Unit",
|
||||||
@ -72,6 +72,12 @@ class HaPanelDevStatistics extends LitElement {
|
|||||||
filterable: true,
|
filterable: true,
|
||||||
width: "10%",
|
width: "10%",
|
||||||
},
|
},
|
||||||
|
source: {
|
||||||
|
title: "Source",
|
||||||
|
sortable: true,
|
||||||
|
filterable: true,
|
||||||
|
width: "10%",
|
||||||
|
},
|
||||||
issues: {
|
issues: {
|
||||||
title: "Issue",
|
title: "Issue",
|
||||||
sortable: true,
|
sortable: true,
|
||||||
@ -146,6 +152,7 @@ class HaPanelDevStatistics extends LitElement {
|
|||||||
this._data.push({
|
this._data.push({
|
||||||
statistic_id: statisticId,
|
statistic_id: statisticId,
|
||||||
unit_of_measurement: "",
|
unit_of_measurement: "",
|
||||||
|
source: "",
|
||||||
state: this.hass.states[statisticId],
|
state: this.hass.states[statisticId],
|
||||||
issues: issues[statisticId],
|
issues: issues[statisticId],
|
||||||
});
|
});
|
||||||
|
@ -78,7 +78,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const configEntities = config.entities
|
const configEntities = config.entities
|
||||||
? processConfigEntities(config.entities)
|
? processConfigEntities(config.entities, false)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
this._entities = [];
|
this._entities = [];
|
||||||
|
@ -52,7 +52,7 @@ export function hasConfigOrEntitiesChanged(
|
|||||||
|
|
||||||
const oldHass = changedProps.get("hass") as HomeAssistant;
|
const oldHass = changedProps.get("hass") as HomeAssistant;
|
||||||
|
|
||||||
const entities = processConfigEntities(element._config!.entities);
|
const entities = processConfigEntities(element._config!.entities, false);
|
||||||
|
|
||||||
return entities.some(
|
return entities.some(
|
||||||
(entity) =>
|
(entity) =>
|
||||||
|
@ -5,7 +5,8 @@ import { EntityConfig, LovelaceRowConfig } from "../entity-rows/types";
|
|||||||
export const processConfigEntities = <
|
export const processConfigEntities = <
|
||||||
T extends EntityConfig | LovelaceRowConfig
|
T extends EntityConfig | LovelaceRowConfig
|
||||||
>(
|
>(
|
||||||
entities: Array<T | string>
|
entities: Array<T | string>,
|
||||||
|
checkEntityId = true
|
||||||
): T[] => {
|
): T[] => {
|
||||||
if (!entities || !Array.isArray(entities)) {
|
if (!entities || !Array.isArray(entities)) {
|
||||||
throw new Error("Entities need to be an array");
|
throw new Error("Entities need to be an array");
|
||||||
@ -35,7 +36,7 @@ export const processConfigEntities = <
|
|||||||
throw new Error(`Invalid entity specified at position ${index}.`);
|
throw new Error(`Invalid entity specified at position ${index}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidEntityId((config as EntityConfig).entity!)) {
|
if (checkEntityId && !isValidEntityId((config as EntityConfig).entity!)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid entity ID at position ${index}: ${
|
`Invalid entity ID at position ${index}: ${
|
||||||
(config as EntityConfig).entity
|
(config as EntityConfig).entity
|
||||||
|
@ -61,7 +61,7 @@ export class HuiStatisticsGraphCardEditor
|
|||||||
assert(config, cardConfigStruct);
|
assert(config, cardConfigStruct);
|
||||||
this._config = config;
|
this._config = config;
|
||||||
this._configEntities = config.entities
|
this._configEntities = config.entities
|
||||||
? processConfigEntities(config.entities).map((cfg) => cfg.entity)
|
? processConfigEntities(config.entities, false).map((cfg) => cfg.entity)
|
||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user