diff --git a/src/dialogs/more-info/ha-more-info-history.ts b/src/dialogs/more-info/ha-more-info-history.ts index 6a316a0ae6..43eaa9fd84 100644 --- a/src/dialogs/more-info/ha-more-info-history.ts +++ b/src/dialogs/more-info/ha-more-info-history.ts @@ -1,4 +1,4 @@ -import { startOfYesterday } from "date-fns/esm"; +import { startOfYesterday, subHours } from "date-fns/esm"; import { css, html, LitElement, PropertyValues, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { isComponentLoaded } from "../../common/config/is_component_loaded"; @@ -7,7 +7,14 @@ import { throttle } from "../../common/util/throttle"; import "../../components/chart/state-history-charts"; import { getRecentWithCache } from "../../data/cached-history"; import { HistoryResult } from "../../data/history"; +import { + fetchStatistics, + getStatisticMetadata, + Statistics, +} from "../../data/recorder"; import { HomeAssistant } from "../../types"; +import "../../components/chart/statistics-chart"; +import { computeDomain } from "../../common/entity/compute_domain"; declare global { interface HASSDomEvents { @@ -15,6 +22,8 @@ declare global { } } +const statTypes = ["state", "min", "mean", "max"]; + @customElement("ha-more-info-history") export class MoreInfoHistory extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -23,6 +32,8 @@ export class MoreInfoHistory extends LitElement { @state() private _stateHistory?: HistoryResult; + @state() private _statistics?: Statistics; + private _showMoreHref = ""; private _throttleGetStateHistory = throttle(() => { @@ -35,7 +46,7 @@ export class MoreInfoHistory extends LitElement { } return html`${isComponentLoaded(this.hass, "history") - ? html`