From d5d6216cfe340db63cf321dd13df6a97f1cee8f4 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 12 Sep 2022 13:23:02 +0200 Subject: [PATCH] Move recorder statistics API to data/recorder.ts (#13672) * Move recorder statistics API to data/recorder.ts * Fix import * prettier --- demo/src/stubs/history.ts | 2 +- src/components/chart/statistics-chart.ts | 2 +- src/components/entity/ha-statistic-picker.ts | 2 +- src/data/energy.ts | 2 +- src/data/history.ts | 215 +----------------- src/data/recorder.ts | 210 +++++++++++++++++ .../components/ha-energy-battery-settings.ts | 2 +- .../components/ha-energy-device-settings.ts | 2 +- .../components/ha-energy-gas-settings.ts | 2 +- .../components/ha-energy-grid-settings.ts | 2 +- .../components/ha-energy-solar-settings.ts | 2 +- src/panels/config/energy/ha-config-energy.ts | 2 +- .../statistics/developer-tools-statistics.ts | 2 +- .../dialog-statistics-adjust-sum.ts | 2 +- .../dialog-statistics-fix-units-changed.ts | 2 +- ...og-statistics-fix-unsupported-unit-meta.ts | 2 +- .../show-dialog-statistics-adjust-sum.ts | 2 +- ...how-dialog-statistics-fix-units-changed.ts | 2 +- ...og-statistics-fix-unsupported-unit-meta.ts | 2 +- .../hui-energy-carbon-consumed-gauge-card.ts | 2 +- .../energy/hui-energy-devices-graph-card.ts | 2 +- .../energy/hui-energy-distribution-card.ts | 2 +- .../cards/energy/hui-energy-gas-graph-card.ts | 2 +- .../hui-energy-grid-neutrality-gauge-card.ts | 2 +- .../hui-energy-solar-consumed-gauge-card.ts | 2 +- .../energy/hui-energy-solar-graph-card.ts | 2 +- .../energy/hui-energy-sources-table-card.ts | 2 +- .../energy/hui-energy-usage-graph-card.ts | 2 +- .../cards/hui-statistics-graph-card.ts | 2 +- src/panels/lovelace/cards/types.ts | 2 +- 30 files changed, 239 insertions(+), 242 deletions(-) create mode 100644 src/data/recorder.ts diff --git a/demo/src/stubs/history.ts b/demo/src/stubs/history.ts index 2e2c507ccc..86f3445956 100644 --- a/demo/src/stubs/history.ts +++ b/demo/src/stubs/history.ts @@ -6,7 +6,7 @@ import { endOfDay, } from "date-fns/esm"; import { HassEntity } from "home-assistant-js-websocket"; -import { StatisticValue } from "../../../src/data/history"; +import { StatisticValue } from "../../../src/data/recorder"; import { MockHomeAssistant } from "../../../src/fake_data/provide_hass"; interface HistoryQueryParams { diff --git a/src/components/chart/statistics-chart.ts b/src/components/chart/statistics-chart.ts index ece8671a8c..50f7e263de 100644 --- a/src/components/chart/statistics-chart.ts +++ b/src/components/chart/statistics-chart.ts @@ -26,7 +26,7 @@ import { statisticsHaveType, StatisticsMetaData, StatisticType, -} from "../../data/history"; +} from "../../data/recorder"; import type { HomeAssistant } from "../../types"; import "./ha-chart-base"; diff --git a/src/components/entity/ha-statistic-picker.ts b/src/components/entity/ha-statistic-picker.ts index a2533c7bb9..1cfabba3d5 100644 --- a/src/components/entity/ha-statistic-picker.ts +++ b/src/components/entity/ha-statistic-picker.ts @@ -6,7 +6,7 @@ import memoizeOne from "memoize-one"; import { fireEvent } from "../../common/dom/fire_event"; import { computeStateName } from "../../common/entity/compute_state_name"; import { stringCompare } from "../../common/string/compare"; -import { getStatisticIds, StatisticsMetaData } from "../../data/history"; +import { getStatisticIds, StatisticsMetaData } from "../../data/recorder"; import { PolymerChangedEvent } from "../../polymer-types"; import { HomeAssistant } from "../../types"; import { documentationUrl } from "../../util/documentation-url"; diff --git a/src/data/energy.ts b/src/data/energy.ts index f9a2c3d862..4c9f4f962d 100644 --- a/src/data/energy.ts +++ b/src/data/energy.ts @@ -20,7 +20,7 @@ import { getStatisticMetadata, Statistics, StatisticsMetaData, -} from "./history"; +} from "./recorder"; const energyCollectionKeys: (string | undefined)[] = []; diff --git a/src/data/history.ts b/src/data/history.ts index b314a3eaef..3f8777588a 100644 --- a/src/data/history.ts +++ b/src/data/history.ts @@ -1,10 +1,7 @@ import { HassEntities, HassEntity } from "home-assistant-js-websocket"; import { computeDomain } from "../common/entity/compute_domain"; import { computeStateDisplayFromEntityAttributes } from "../common/entity/compute_state_display"; -import { - computeStateName, - computeStateNameFromEntityAttributes, -} from "../common/entity/compute_state_name"; +import { computeStateNameFromEntityAttributes } from "../common/entity/compute_state_name"; import { LocalizeFunc } from "../common/translations/localize"; import { HomeAssistant } from "../types"; import { FrontendLocaleData } from "./translation"; @@ -63,87 +60,6 @@ export interface HistoryResult { timeline: TimelineEntity[]; } -export type StatisticType = "sum" | "min" | "max" | "mean"; - -export interface Statistics { - [statisticId: string]: StatisticValue[]; -} - -export interface StatisticValue { - statistic_id: string; - start: string; - end: string; - last_reset: string | null; - max: number | null; - mean: number | null; - min: number | null; - sum: number | null; - state: number | null; -} - -export interface StatisticsMetaData { - display_unit_of_measurement: string; - statistics_unit_of_measurement: string; - statistic_id: string; - source: string; - name?: string | null; - has_sum: boolean; - has_mean: boolean; -} - -export type StatisticsValidationResult = - | StatisticsValidationResultNoState - | StatisticsValidationResultEntityNotRecorded - | StatisticsValidationResultEntityNoLongerRecorded - | StatisticsValidationResultUnsupportedStateClass - | StatisticsValidationResultUnitsChanged - | StatisticsValidationResultUnsupportedUnitMetadata - | StatisticsValidationResultUnsupportedUnitState; - -export interface StatisticsValidationResultNoState { - type: "no_state"; - data: { statistic_id: string }; -} - -export interface StatisticsValidationResultEntityNoLongerRecorded { - type: "entity_no_longer_recorded"; - data: { statistic_id: string }; -} - -export interface StatisticsValidationResultEntityNotRecorded { - type: "entity_not_recorded"; - data: { statistic_id: string }; -} - -export interface StatisticsValidationResultUnsupportedStateClass { - type: "unsupported_state_class"; - data: { statistic_id: string; state_class: string }; -} - -export interface StatisticsValidationResultUnitsChanged { - type: "units_changed"; - data: { statistic_id: string; state_unit: string; metadata_unit: string }; -} - -export interface StatisticsValidationResultUnsupportedUnitMetadata { - type: "unsupported_unit_metadata"; - data: { - statistic_id: string; - device_class: string; - metadata_unit: string; - supported_unit: string; - }; -} - -export interface StatisticsValidationResultUnsupportedUnitState { - type: "unsupported_unit_state"; - data: { statistic_id: string; device_class: string; metadata_unit: string }; -} - -export interface StatisticsValidationResults { - [statisticId: string]: StatisticsValidationResult[]; -} - export interface HistoryStates { [entityId: string]: EntityHistoryState[]; } @@ -449,132 +365,3 @@ export const computeHistory = ( return { line: unitStates, timeline: timelineDevices }; }; - -// Statistics - -export const getStatisticIds = ( - hass: HomeAssistant, - statistic_type?: "mean" | "sum" -) => - hass.callWS({ - type: "recorder/list_statistic_ids", - statistic_type, - }); - -export const getStatisticMetadata = ( - hass: HomeAssistant, - statistic_ids?: string[] -) => - hass.callWS({ - type: "recorder/get_statistics_metadata", - statistic_ids, - }); - -export const fetchStatistics = ( - hass: HomeAssistant, - startTime: Date, - endTime?: Date, - statistic_ids?: string[], - period: "5minute" | "hour" | "day" | "month" = "hour" -) => - hass.callWS({ - type: "recorder/statistics_during_period", - start_time: startTime.toISOString(), - end_time: endTime?.toISOString(), - statistic_ids, - period, - }); - -export const validateStatistics = (hass: HomeAssistant) => - hass.callWS({ - type: "recorder/validate_statistics", - }); - -export const updateStatisticsMetadata = ( - hass: HomeAssistant, - statistic_id: string, - unit_of_measurement: string | null -) => - hass.callWS({ - type: "recorder/update_statistics_metadata", - statistic_id, - unit_of_measurement, - }); - -export const clearStatistics = (hass: HomeAssistant, statistic_ids: string[]) => - hass.callWS({ - type: "recorder/clear_statistics", - statistic_ids, - }); - -export const calculateStatisticSumGrowth = ( - values: StatisticValue[] -): number | null => { - if (!values || values.length < 2) { - return null; - } - const endSum = values[values.length - 1].sum; - if (endSum === null) { - return null; - } - const startSum = values[0].sum; - if (startSum === null) { - return endSum; - } - return endSum - startSum; -}; - -export const calculateStatisticsSumGrowth = ( - data: Statistics, - stats: string[] -): number | null => { - let totalGrowth: number | null = null; - - for (const stat of stats) { - if (!(stat in data)) { - continue; - } - const statGrowth = calculateStatisticSumGrowth(data[stat]); - - if (statGrowth === null) { - continue; - } - if (totalGrowth === null) { - totalGrowth = statGrowth; - } else { - totalGrowth += statGrowth; - } - } - - return totalGrowth; -}; - -export const statisticsHaveType = ( - stats: StatisticValue[], - type: StatisticType -) => stats.some((stat) => stat[type] !== null); - -export const adjustStatisticsSum = ( - hass: HomeAssistant, - statistic_id: string, - start_time: string, - adjustment: number -): Promise => - hass.callWS({ - type: "recorder/adjust_sum_statistics", - statistic_id, - start_time, - adjustment, - }); - -export const getStatisticLabel = ( - hass: HomeAssistant, - statisticsId: string, - statisticsMetaData: StatisticsMetaData | undefined -): string => { - const entity = hass.states[statisticsId]; - if (entity) { - return computeStateName(entity); - } - return statisticsMetaData?.name || statisticsId; -}; diff --git a/src/data/recorder.ts b/src/data/recorder.ts new file mode 100644 index 0000000000..4022b83042 --- /dev/null +++ b/src/data/recorder.ts @@ -0,0 +1,210 @@ +import { computeStateName } from "../common/entity/compute_state_name"; +import { HomeAssistant } from "../types"; + +export type StatisticType = "sum" | "min" | "max" | "mean"; + +export interface Statistics { + [statisticId: string]: StatisticValue[]; +} + +export interface StatisticValue { + statistic_id: string; + start: string; + end: string; + last_reset: string | null; + max: number | null; + mean: number | null; + min: number | null; + sum: number | null; + state: number | null; +} + +export interface StatisticsMetaData { + display_unit_of_measurement: string; + statistics_unit_of_measurement: string; + statistic_id: string; + source: string; + name?: string | null; + has_sum: boolean; + has_mean: boolean; +} + +export type StatisticsValidationResult = + | StatisticsValidationResultNoState + | StatisticsValidationResultEntityNotRecorded + | StatisticsValidationResultEntityNoLongerRecorded + | StatisticsValidationResultUnsupportedStateClass + | StatisticsValidationResultUnitsChanged + | StatisticsValidationResultUnsupportedUnitMetadata + | StatisticsValidationResultUnsupportedUnitState; + +export interface StatisticsValidationResultNoState { + type: "no_state"; + data: { statistic_id: string }; +} + +export interface StatisticsValidationResultEntityNoLongerRecorded { + type: "entity_no_longer_recorded"; + data: { statistic_id: string }; +} + +export interface StatisticsValidationResultEntityNotRecorded { + type: "entity_not_recorded"; + data: { statistic_id: string }; +} + +export interface StatisticsValidationResultUnsupportedStateClass { + type: "unsupported_state_class"; + data: { statistic_id: string; state_class: string }; +} + +export interface StatisticsValidationResultUnitsChanged { + type: "units_changed"; + data: { statistic_id: string; state_unit: string; metadata_unit: string }; +} + +export interface StatisticsValidationResultUnsupportedUnitMetadata { + type: "unsupported_unit_metadata"; + data: { + statistic_id: string; + device_class: string; + metadata_unit: string; + supported_unit: string; + }; +} + +export interface StatisticsValidationResultUnsupportedUnitState { + type: "unsupported_unit_state"; + data: { statistic_id: string; device_class: string; metadata_unit: string }; +} + +export interface StatisticsValidationResults { + [statisticId: string]: StatisticsValidationResult[]; +} + +export const getStatisticIds = ( + hass: HomeAssistant, + statistic_type?: "mean" | "sum" +) => + hass.callWS({ + type: "recorder/list_statistic_ids", + statistic_type, + }); + +export const getStatisticMetadata = ( + hass: HomeAssistant, + statistic_ids?: string[] +) => + hass.callWS({ + type: "recorder/get_statistics_metadata", + statistic_ids, + }); + +export const fetchStatistics = ( + hass: HomeAssistant, + startTime: Date, + endTime?: Date, + statistic_ids?: string[], + period: "5minute" | "hour" | "day" | "month" = "hour" +) => + hass.callWS({ + type: "recorder/statistics_during_period", + start_time: startTime.toISOString(), + end_time: endTime?.toISOString(), + statistic_ids, + period, + }); + +export const validateStatistics = (hass: HomeAssistant) => + hass.callWS({ + type: "recorder/validate_statistics", + }); + +export const updateStatisticsMetadata = ( + hass: HomeAssistant, + statistic_id: string, + unit_of_measurement: string | null +) => + hass.callWS({ + type: "recorder/update_statistics_metadata", + statistic_id, + unit_of_measurement, + }); + +export const clearStatistics = (hass: HomeAssistant, statistic_ids: string[]) => + hass.callWS({ + type: "recorder/clear_statistics", + statistic_ids, + }); + +export const calculateStatisticSumGrowth = ( + values: StatisticValue[] +): number | null => { + if (!values || values.length < 2) { + return null; + } + const endSum = values[values.length - 1].sum; + if (endSum === null) { + return null; + } + const startSum = values[0].sum; + if (startSum === null) { + return endSum; + } + return endSum - startSum; +}; + +export const calculateStatisticsSumGrowth = ( + data: Statistics, + stats: string[] +): number | null => { + let totalGrowth: number | null = null; + + for (const stat of stats) { + if (!(stat in data)) { + continue; + } + const statGrowth = calculateStatisticSumGrowth(data[stat]); + + if (statGrowth === null) { + continue; + } + if (totalGrowth === null) { + totalGrowth = statGrowth; + } else { + totalGrowth += statGrowth; + } + } + + return totalGrowth; +}; + +export const statisticsHaveType = ( + stats: StatisticValue[], + type: StatisticType +) => stats.some((stat) => stat[type] !== null); + +export const adjustStatisticsSum = ( + hass: HomeAssistant, + statistic_id: string, + start_time: string, + adjustment: number +): Promise => + hass.callWS({ + type: "recorder/adjust_sum_statistics", + statistic_id, + start_time, + adjustment, + }); + +export const getStatisticLabel = ( + hass: HomeAssistant, + statisticsId: string, + statisticsMetaData: StatisticsMetaData | undefined +): string => { + const entity = hass.states[statisticsId]; + if (entity) { + return computeStateName(entity); + } + return statisticsMetaData?.name || statisticsId; +}; diff --git a/src/panels/config/energy/components/ha-energy-battery-settings.ts b/src/panels/config/energy/components/ha-energy-battery-settings.ts index 376ace7323..9a7b3c6ad1 100644 --- a/src/panels/config/energy/components/ha-energy-battery-settings.ts +++ b/src/panels/config/energy/components/ha-energy-battery-settings.ts @@ -16,7 +16,7 @@ import { import { StatisticsMetaData, getStatisticLabel, -} from "../../../../data/history"; +} from "../../../../data/recorder"; import { showAlertDialog, showConfirmationDialog, diff --git a/src/panels/config/energy/components/ha-energy-device-settings.ts b/src/panels/config/energy/components/ha-energy-device-settings.ts index bac990fbc8..1d03ed1326 100644 --- a/src/panels/config/energy/components/ha-energy-device-settings.ts +++ b/src/panels/config/energy/components/ha-energy-device-settings.ts @@ -15,7 +15,7 @@ import { import { StatisticsMetaData, getStatisticLabel, -} from "../../../../data/history"; +} from "../../../../data/recorder"; import { showAlertDialog, showConfirmationDialog, diff --git a/src/panels/config/energy/components/ha-energy-gas-settings.ts b/src/panels/config/energy/components/ha-energy-gas-settings.ts index 29b81e2a85..44f2d4b2ba 100644 --- a/src/panels/config/energy/components/ha-energy-gas-settings.ts +++ b/src/panels/config/energy/components/ha-energy-gas-settings.ts @@ -16,7 +16,7 @@ import { import { StatisticsMetaData, getStatisticLabel, -} from "../../../../data/history"; +} from "../../../../data/recorder"; import { showAlertDialog, showConfirmationDialog, diff --git a/src/panels/config/energy/components/ha-energy-grid-settings.ts b/src/panels/config/energy/components/ha-energy-grid-settings.ts index 0e78a01b95..e4e85d79c4 100644 --- a/src/panels/config/energy/components/ha-energy-grid-settings.ts +++ b/src/panels/config/energy/components/ha-energy-grid-settings.ts @@ -30,7 +30,7 @@ import { import { StatisticsMetaData, getStatisticLabel, -} from "../../../../data/history"; +} from "../../../../data/recorder"; import { showConfigFlowDialog } from "../../../../dialogs/config-flow/show-dialog-config-flow"; import { showAlertDialog, diff --git a/src/panels/config/energy/components/ha-energy-solar-settings.ts b/src/panels/config/energy/components/ha-energy-solar-settings.ts index 8c8aef7ac1..a29faaeb76 100644 --- a/src/panels/config/energy/components/ha-energy-solar-settings.ts +++ b/src/panels/config/energy/components/ha-energy-solar-settings.ts @@ -16,7 +16,7 @@ import { import { StatisticsMetaData, getStatisticLabel, -} from "../../../../data/history"; +} from "../../../../data/recorder"; import { showConfirmationDialog, showAlertDialog, diff --git a/src/panels/config/energy/ha-config-energy.ts b/src/panels/config/energy/ha-config-energy.ts index c6a2d5b150..d779876137 100644 --- a/src/panels/config/energy/ha-config-energy.ts +++ b/src/panels/config/energy/ha-config-energy.ts @@ -13,7 +13,7 @@ import { import { getStatisticMetadata, StatisticsMetaData, -} from "../../../data/history"; +} from "../../../data/recorder"; import "../../../layouts/hass-loading-screen"; import "../../../layouts/hass-subpage"; import { haStyle } from "../../../resources/styles"; diff --git a/src/panels/developer-tools/statistics/developer-tools-statistics.ts b/src/panels/developer-tools/statistics/developer-tools-statistics.ts index cf0847bb05..980fabaa52 100644 --- a/src/panels/developer-tools/statistics/developer-tools-statistics.ts +++ b/src/panels/developer-tools/statistics/developer-tools-statistics.ts @@ -15,7 +15,7 @@ import { StatisticsMetaData, StatisticsValidationResult, validateStatistics, -} from "../../../data/history"; +} from "../../../data/recorder"; import { showAlertDialog, showConfirmationDialog, diff --git a/src/panels/developer-tools/statistics/dialog-statistics-adjust-sum.ts b/src/panels/developer-tools/statistics/dialog-statistics-adjust-sum.ts index ded0fc2c82..b9c54f3f6a 100644 --- a/src/panels/developer-tools/statistics/dialog-statistics-adjust-sum.ts +++ b/src/panels/developer-tools/statistics/dialog-statistics-adjust-sum.ts @@ -24,7 +24,7 @@ import { adjustStatisticsSum, fetchStatistics, StatisticValue, -} from "../../../data/history"; +} from "../../../data/recorder"; import type { DateTimeSelector, NumberSelector } from "../../../data/selector"; import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box"; import { haStyle, haStyleDialog } from "../../../resources/styles"; diff --git a/src/panels/developer-tools/statistics/dialog-statistics-fix-units-changed.ts b/src/panels/developer-tools/statistics/dialog-statistics-fix-units-changed.ts index 3168bffc9f..5d11ba98ed 100644 --- a/src/panels/developer-tools/statistics/dialog-statistics-fix-units-changed.ts +++ b/src/panels/developer-tools/statistics/dialog-statistics-fix-units-changed.ts @@ -8,7 +8,7 @@ import { HomeAssistant } from "../../../types"; import { clearStatistics, updateStatisticsMetadata, -} from "../../../data/history"; +} from "../../../data/recorder"; import "../../../components/ha-formfield"; import "../../../components/ha-radio"; import type { DialogStatisticsUnitsChangedParams } from "./show-dialog-statistics-fix-units-changed"; diff --git a/src/panels/developer-tools/statistics/dialog-statistics-fix-unsupported-unit-meta.ts b/src/panels/developer-tools/statistics/dialog-statistics-fix-unsupported-unit-meta.ts index 4bfaebe489..0058fa49d2 100644 --- a/src/panels/developer-tools/statistics/dialog-statistics-fix-unsupported-unit-meta.ts +++ b/src/panels/developer-tools/statistics/dialog-statistics-fix-unsupported-unit-meta.ts @@ -5,7 +5,7 @@ import "../../../components/ha-dialog"; import { fireEvent } from "../../../common/dom/fire_event"; import { haStyle, haStyleDialog } from "../../../resources/styles"; import { HomeAssistant } from "../../../types"; -import { updateStatisticsMetadata } from "../../../data/history"; +import { updateStatisticsMetadata } from "../../../data/recorder"; import "../../../components/ha-formfield"; import "../../../components/ha-radio"; import type { DialogStatisticsUnsupportedUnitMetaParams } from "./show-dialog-statistics-fix-unsupported-unit-meta"; diff --git a/src/panels/developer-tools/statistics/show-dialog-statistics-adjust-sum.ts b/src/panels/developer-tools/statistics/show-dialog-statistics-adjust-sum.ts index 1db2c76307..6248a6c42f 100644 --- a/src/panels/developer-tools/statistics/show-dialog-statistics-adjust-sum.ts +++ b/src/panels/developer-tools/statistics/show-dialog-statistics-adjust-sum.ts @@ -1,5 +1,5 @@ import { fireEvent } from "../../../common/dom/fire_event"; -import { StatisticsMetaData } from "../../../data/history"; +import { StatisticsMetaData } from "../../../data/recorder"; export const loadAdjustSumDialog = () => import("./dialog-statistics-adjust-sum"); diff --git a/src/panels/developer-tools/statistics/show-dialog-statistics-fix-units-changed.ts b/src/panels/developer-tools/statistics/show-dialog-statistics-fix-units-changed.ts index c341bfdf21..1b6d7ee116 100644 --- a/src/panels/developer-tools/statistics/show-dialog-statistics-fix-units-changed.ts +++ b/src/panels/developer-tools/statistics/show-dialog-statistics-fix-units-changed.ts @@ -1,5 +1,5 @@ import { fireEvent } from "../../../common/dom/fire_event"; -import { StatisticsValidationResultUnitsChanged } from "../../../data/history"; +import { StatisticsValidationResultUnitsChanged } from "../../../data/recorder"; export const loadFixUnitsDialog = () => import("./dialog-statistics-fix-units-changed"); diff --git a/src/panels/developer-tools/statistics/show-dialog-statistics-fix-unsupported-unit-meta.ts b/src/panels/developer-tools/statistics/show-dialog-statistics-fix-unsupported-unit-meta.ts index 828f3094bc..8ea4c5d915 100644 --- a/src/panels/developer-tools/statistics/show-dialog-statistics-fix-unsupported-unit-meta.ts +++ b/src/panels/developer-tools/statistics/show-dialog-statistics-fix-unsupported-unit-meta.ts @@ -1,5 +1,5 @@ import { fireEvent } from "../../../common/dom/fire_event"; -import { StatisticsValidationResultUnsupportedUnitMetadata } from "../../../data/history"; +import { StatisticsValidationResultUnsupportedUnitMetadata } from "../../../data/recorder"; export const loadFixUnsupportedUnitMetaDialog = () => import("./dialog-statistics-fix-unsupported-unit-meta"); diff --git a/src/panels/lovelace/cards/energy/hui-energy-carbon-consumed-gauge-card.ts b/src/panels/lovelace/cards/energy/hui-energy-carbon-consumed-gauge-card.ts index ea2c81d949..20dce6b0f6 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-carbon-consumed-gauge-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-carbon-consumed-gauge-card.ts @@ -13,7 +13,7 @@ import { energySourcesByType, getEnergyDataCollection, } from "../../../../data/energy"; -import { calculateStatisticsSumGrowth } from "../../../../data/history"; +import { calculateStatisticsSumGrowth } from "../../../../data/recorder"; import { SubscribeMixin } from "../../../../mixins/subscribe-mixin"; import type { HomeAssistant } from "../../../../types"; import { createEntityNotFoundWarning } from "../../components/hui-warning"; diff --git a/src/panels/lovelace/cards/energy/hui-energy-devices-graph-card.ts b/src/panels/lovelace/cards/energy/hui-energy-devices-graph-card.ts index a1419466c5..10cab6c299 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-devices-graph-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-devices-graph-card.ts @@ -27,7 +27,7 @@ import { fetchStatistics, getStatisticLabel, Statistics, -} from "../../../../data/history"; +} from "../../../../data/recorder"; import { FrontendLocaleData } from "../../../../data/translation"; import { SubscribeMixin } from "../../../../mixins/subscribe-mixin"; import { HomeAssistant } from "../../../../types"; diff --git a/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts b/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts index d42863015f..d204562559 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts @@ -24,7 +24,7 @@ import { getEnergyDataCollection, getEnergyGasUnit, } from "../../../../data/energy"; -import { calculateStatisticsSumGrowth } from "../../../../data/history"; +import { calculateStatisticsSumGrowth } from "../../../../data/recorder"; import { SubscribeMixin } from "../../../../mixins/subscribe-mixin"; import { HomeAssistant } from "../../../../types"; import { LovelaceCard } from "../../types"; diff --git a/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts b/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts index 6ec689b4f8..fc940d5605 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts @@ -42,7 +42,7 @@ import { Statistics, StatisticsMetaData, getStatisticLabel, -} from "../../../../data/history"; +} from "../../../../data/recorder"; import { FrontendLocaleData } from "../../../../data/translation"; import { SubscribeMixin } from "../../../../mixins/subscribe-mixin"; import { HomeAssistant } from "../../../../types"; diff --git a/src/panels/lovelace/cards/energy/hui-energy-grid-neutrality-gauge-card.ts b/src/panels/lovelace/cards/energy/hui-energy-grid-neutrality-gauge-card.ts index 9e6ad9edec..1b3897b7d1 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-grid-neutrality-gauge-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-grid-neutrality-gauge-card.ts @@ -13,7 +13,7 @@ import { getEnergyDataCollection, GridSourceTypeEnergyPreference, } from "../../../../data/energy"; -import { calculateStatisticsSumGrowth } from "../../../../data/history"; +import { calculateStatisticsSumGrowth } from "../../../../data/recorder"; import { SubscribeMixin } from "../../../../mixins/subscribe-mixin"; import type { HomeAssistant } from "../../../../types"; import type { LovelaceCard } from "../../types"; diff --git a/src/panels/lovelace/cards/energy/hui-energy-solar-consumed-gauge-card.ts b/src/panels/lovelace/cards/energy/hui-energy-solar-consumed-gauge-card.ts index c7c8f3c829..5e5df30f85 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-solar-consumed-gauge-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-solar-consumed-gauge-card.ts @@ -12,7 +12,7 @@ import { energySourcesByType, getEnergyDataCollection, } from "../../../../data/energy"; -import { calculateStatisticsSumGrowth } from "../../../../data/history"; +import { calculateStatisticsSumGrowth } from "../../../../data/recorder"; import { SubscribeMixin } from "../../../../mixins/subscribe-mixin"; import type { HomeAssistant } from "../../../../types"; import type { LovelaceCard } from "../../types"; diff --git a/src/panels/lovelace/cards/energy/hui-energy-solar-graph-card.ts b/src/panels/lovelace/cards/energy/hui-energy-solar-graph-card.ts index 5b29e94c53..ac985edef9 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-solar-graph-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-solar-graph-card.ts @@ -43,7 +43,7 @@ import { Statistics, StatisticsMetaData, getStatisticLabel, -} from "../../../../data/history"; +} from "../../../../data/recorder"; import { FrontendLocaleData } from "../../../../data/translation"; import { SubscribeMixin } from "../../../../mixins/subscribe-mixin"; import { HomeAssistant } from "../../../../types"; diff --git a/src/panels/lovelace/cards/energy/hui-energy-sources-table-card.ts b/src/panels/lovelace/cards/energy/hui-energy-sources-table-card.ts index ec1c20ee45..64779926c3 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-sources-table-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-sources-table-card.ts @@ -30,7 +30,7 @@ import { import { calculateStatisticSumGrowth, getStatisticLabel, -} from "../../../../data/history"; +} from "../../../../data/recorder"; import { SubscribeMixin } from "../../../../mixins/subscribe-mixin"; import { HomeAssistant } from "../../../../types"; import { LovelaceCard } from "../../types"; diff --git a/src/panels/lovelace/cards/energy/hui-energy-usage-graph-card.ts b/src/panels/lovelace/cards/energy/hui-energy-usage-graph-card.ts index 1e315bcc37..ebae24dfca 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-usage-graph-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-usage-graph-card.ts @@ -37,7 +37,7 @@ import { Statistics, StatisticsMetaData, getStatisticLabel, -} from "../../../../data/history"; +} from "../../../../data/recorder"; import { FrontendLocaleData } from "../../../../data/translation"; import { SubscribeMixin } from "../../../../mixins/subscribe-mixin"; import { HomeAssistant } from "../../../../types"; diff --git a/src/panels/lovelace/cards/hui-statistics-graph-card.ts b/src/panels/lovelace/cards/hui-statistics-graph-card.ts index 370857f9f0..4a6f4d39c7 100644 --- a/src/panels/lovelace/cards/hui-statistics-graph-card.ts +++ b/src/panels/lovelace/cards/hui-statistics-graph-card.ts @@ -15,7 +15,7 @@ import { hasConfigOrEntitiesChanged } from "../common/has-changed"; import { processConfigEntities } from "../common/process-config-entities"; import { LovelaceCard } from "../types"; import { StatisticsGraphCardConfig } from "./types"; -import { fetchStatistics, Statistics } from "../../../data/history"; +import { fetchStatistics, Statistics } from "../../../data/recorder"; @customElement("hui-statistics-graph-card") export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard { diff --git a/src/panels/lovelace/cards/types.ts b/src/panels/lovelace/cards/types.ts index ffd0cc3555..7113ad1d13 100644 --- a/src/panels/lovelace/cards/types.ts +++ b/src/panels/lovelace/cards/types.ts @@ -1,4 +1,4 @@ -import { StatisticType } from "../../../data/history"; +import { StatisticType } from "../../../data/recorder"; import { ActionConfig, LovelaceCardConfig } from "../../../data/lovelace"; import { FullCalendarView, TranslationDict } from "../../../types"; import { Condition } from "../common/validate-condition";