mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-31 21:17:47 +00:00
Change stat_types to supported ones for statistics
This commit is contained in:
parent
95bbf6e0d2
commit
72ad0f0f61
@ -1,7 +1,7 @@
|
|||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../common/entity/compute_state_name";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
|
|
||||||
export type StatisticType = "sum" | "min" | "max" | "mean";
|
export type StatisticType = "state" | "sum" | "min" | "max" | "mean";
|
||||||
|
|
||||||
export interface Statistics {
|
export interface Statistics {
|
||||||
[statisticId: string]: StatisticValue[];
|
[statisticId: string]: StatisticValue[];
|
||||||
|
@ -90,7 +90,10 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
|||||||
if (typeof config.stat_types === "string") {
|
if (typeof config.stat_types === "string") {
|
||||||
this._config = { ...config, stat_types: [config.stat_types] };
|
this._config = { ...config, stat_types: [config.stat_types] };
|
||||||
} else if (!config.stat_types) {
|
} else if (!config.stat_types) {
|
||||||
this._config = { ...config, stat_types: ["sum", "min", "max", "mean"] };
|
this._config = {
|
||||||
|
...config,
|
||||||
|
stat_types: ["state", "sum", "min", "max", "mean"],
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
this._config = config;
|
this._config = config;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ import {
|
|||||||
} from "../../../../data/recorder";
|
} from "../../../../data/recorder";
|
||||||
import { deepEqual } from "../../../../common/util/deep-equal";
|
import { deepEqual } from "../../../../common/util/deep-equal";
|
||||||
import { statTypeMap } from "../../../../components/chart/statistics-chart";
|
import { statTypeMap } from "../../../../components/chart/statistics-chart";
|
||||||
|
import { ensureArray } from "../../../../common/ensure-array";
|
||||||
|
|
||||||
const statTypeStruct = union([
|
const statTypeStruct = union([
|
||||||
literal("state"),
|
literal("state"),
|
||||||
@ -192,7 +193,11 @@ export class HuiStatisticsGraphCardEditor
|
|||||||
? Array.isArray(this._config!.stat_types)
|
? Array.isArray(this._config!.stat_types)
|
||||||
? this._config!.stat_types
|
? this._config!.stat_types
|
||||||
: [this._config!.stat_types]
|
: [this._config!.stat_types]
|
||||||
: stat_types;
|
: stat_types.filter((stat_type) =>
|
||||||
|
this._metaDatas?.every((metaData) =>
|
||||||
|
statisticsMetaHasType(metaData, statTypeMap[stat_type])
|
||||||
|
)
|
||||||
|
);
|
||||||
const data = {
|
const data = {
|
||||||
chart_type: "line",
|
chart_type: "line",
|
||||||
period: "hour",
|
period: "hour",
|
||||||
@ -232,7 +237,7 @@ export class HuiStatisticsGraphCardEditor
|
|||||||
fireEvent(this, "config-changed", { config: ev.detail.value });
|
fireEvent(this, "config-changed", { config: ev.detail.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
private _entitiesChanged(ev: CustomEvent): void {
|
private async _entitiesChanged(ev: CustomEvent): Promise<void> {
|
||||||
const config = { ...this._config!, entities: ev.detail.value };
|
const config = { ...this._config!, entities: ev.detail.value };
|
||||||
if (
|
if (
|
||||||
config.entities?.some((statistic_id) => statistic_id.includes(":")) &&
|
config.entities?.some((statistic_id) => statistic_id.includes(":")) &&
|
||||||
@ -240,6 +245,17 @@ export class HuiStatisticsGraphCardEditor
|
|||||||
) {
|
) {
|
||||||
delete config.period;
|
delete config.period;
|
||||||
}
|
}
|
||||||
|
if (config.stat_types && config.entities.length) {
|
||||||
|
const metadata = await getStatisticMetadata(this.hass!, config.entities);
|
||||||
|
config.stat_types = ensureArray(config.stat_types).filter((stat_type) =>
|
||||||
|
metadata.every((metaData) =>
|
||||||
|
statisticsMetaHasType(metaData, statTypeMap[stat_type])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (!config.stat_types.length) {
|
||||||
|
delete config.stat_types;
|
||||||
|
}
|
||||||
|
}
|
||||||
fireEvent(this, "config-changed", {
|
fireEvent(this, "config-changed", {
|
||||||
config,
|
config,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user