Fix showing a statistics graph with type 'change' (#14622)

This commit is contained in:
Erik Montnemery 2022-12-08 11:37:57 +01:00 committed by GitHub
parent 3b51050b52
commit d1b1eecd92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View File

@ -32,7 +32,7 @@ import {
import type { HomeAssistant } from "../../types";
import "./ha-chart-base";
export type ExtendedStatisticType = StatisticType | "state" | "change";
export type ExtendedStatisticType = StatisticType | "change";
export const statTypeMap: Record<ExtendedStatisticType, StatisticType> = {
mean: "mean",

View File

@ -9,7 +9,10 @@ import {
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import "../../../components/chart/statistics-chart";
import {
ExtendedStatisticType,
statTypeMap,
} from "../../../components/chart/statistics-chart";
import "../../../components/ha-card";
import {
fetchStatistics,
@ -17,7 +20,6 @@ import {
getStatisticMetadata,
Statistics,
StatisticsMetaData,
StatisticsTypes,
} from "../../../data/recorder";
import { HomeAssistant } from "../../../types";
import { findEntities } from "../common/find-entities";
@ -70,7 +72,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
private _interval?: number;
private _statTypes?: StatisticsTypes;
private _statTypes?: Array<ExtendedStatisticType>;
public disconnectedCallback() {
super.disconnectedCallback();
@ -249,7 +251,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
this._entities,
this._config!.period,
unitconfig,
this._statTypes
this._statTypes?.map((stat_type) => statTypeMap[stat_type])
);
} catch (err) {
this._statistics = undefined;

View File

@ -1,4 +1,4 @@
import { Statistic, StatisticType } from "../../../data/recorder";
import { Statistic } from "../../../data/recorder";
import { ActionConfig, LovelaceCardConfig } from "../../../data/lovelace";
import { FullCalendarView, TranslationDict } from "../../../types";
import { Condition } from "../common/validate-condition";
@ -10,6 +10,7 @@ import {
LovelaceRowConfig,
} from "../entity-rows/types";
import { LovelaceHeaderFooterConfig } from "../header-footer/types";
import { ExtendedStatisticType } from "../../../components/chart/statistics-chart";
import { HaDurationData } from "../../../components/ha-duration-input";
import { LovelaceTileFeatureConfig } from "../tile-features/types";
@ -309,7 +310,7 @@ export interface StatisticsGraphCardConfig extends LovelaceCardConfig {
unit?: string;
days_to_show?: number;
period?: "5minute" | "hour" | "day" | "month";
stat_types?: StatisticType | StatisticType[];
stat_types?: ExtendedStatisticType | ExtendedStatisticType[];
chart_type?: "line" | "bar";
}