Fix statistics graph card (#14631)

This commit is contained in:
Bram Kragten 2022-12-08 13:20:01 +01:00 committed by GitHub
parent ba09120ff3
commit 8c69c772d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -34,7 +34,10 @@ import "./ha-chart-base";
export type ExtendedStatisticType = StatisticType | "change";
export const statTypeMap: Record<ExtendedStatisticType, StatisticType> = {
export const supportedStatTypeMap: Record<
ExtendedStatisticType,
StatisticType
> = {
mean: "mean",
min: "min",
max: "max",
@ -43,6 +46,15 @@ export const statTypeMap: Record<ExtendedStatisticType, StatisticType> = {
change: "sum",
};
export const statTypeMap: Record<ExtendedStatisticType, StatisticType> = {
mean: "mean",
min: "min",
max: "max",
sum: "sum",
state: "state",
change: "sum",
};
@customElement("statistics-chart")
class StatisticsChart extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

View File

@ -154,7 +154,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
if (
changedProps.has("_config") &&
(oldConfig?.entities !== this._config.entities ||
(oldConfig?.stat_types !== this._config.stat_types ||
oldConfig?.days_to_show !== this._config.days_to_show ||
oldConfig?.period !== this._config.period ||
oldConfig?.unit !== this._config.unit)

View File

@ -26,6 +26,7 @@ import { deepEqual } from "../../../../common/util/deep-equal";
import {
ExtendedStatisticType,
statTypeMap,
supportedStatTypeMap,
} from "../../../../components/chart/statistics-chart";
import "../../../../components/entity/ha-statistics-picker";
import "../../../../components/ha-form/ha-form";
@ -185,7 +186,10 @@ export class HuiStatisticsGraphCardEditor
disabled:
!metaDatas ||
!metaDatas.every((metaData) =>
statisticsMetaHasType(metaData, statTypeMap[stat_type])
statisticsMetaHasType(
metaData,
supportedStatTypeMap[stat_type]
)
),
})),
},