mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Adapt energy to core changes (#13779)
This commit is contained in:
parent
4b8960c236
commit
04181e9c28
@ -20,6 +20,7 @@ import {
|
||||
getStatisticMetadata,
|
||||
Statistics,
|
||||
StatisticsMetaData,
|
||||
StatisticsUnitConfiguration,
|
||||
} from "./recorder";
|
||||
|
||||
const energyCollectionKeys: (string | undefined)[] = [];
|
||||
@ -358,12 +359,19 @@ const getEnergyData = async (
|
||||
// Subtract 1 hour from start to get starting point data
|
||||
const startMinHour = addHours(start, -1);
|
||||
|
||||
const lengthUnit = hass.config.unit_system.length || "";
|
||||
const units: StatisticsUnitConfiguration = {
|
||||
energy: "kWh",
|
||||
volume: lengthUnit === "km" ? "m³" : "ft³",
|
||||
};
|
||||
|
||||
const stats = await fetchStatistics(
|
||||
hass!,
|
||||
startMinHour,
|
||||
end,
|
||||
statIDs,
|
||||
period
|
||||
period,
|
||||
units
|
||||
);
|
||||
|
||||
let statsCompare;
|
||||
@ -385,7 +393,8 @@ const getEnergyData = async (
|
||||
compareStartMinHour,
|
||||
endCompare,
|
||||
statIDs,
|
||||
period
|
||||
period,
|
||||
units
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,23 @@ export interface StatisticsValidationResultUnsupportedUnitMetadata {
|
||||
};
|
||||
}
|
||||
|
||||
export interface StatisticsUnitConfiguration {
|
||||
energy?: "Wh" | "kWh" | "MWh";
|
||||
power?: "W" | "kW";
|
||||
pressure?:
|
||||
| "Pa"
|
||||
| "hPa"
|
||||
| "kPa"
|
||||
| "bar"
|
||||
| "cbar"
|
||||
| "mbar"
|
||||
| "inHg"
|
||||
| "psi"
|
||||
| "mmHg";
|
||||
temperature?: "°C" | "°F" | "K";
|
||||
volume?: "ft³" | "m³";
|
||||
}
|
||||
|
||||
export interface StatisticsValidationResultUnsupportedUnitState {
|
||||
type: "unsupported_unit_state";
|
||||
data: { statistic_id: string; device_class: string; metadata_unit: string };
|
||||
@ -105,7 +122,8 @@ export const fetchStatistics = (
|
||||
startTime: Date,
|
||||
endTime?: Date,
|
||||
statistic_ids?: string[],
|
||||
period: "5minute" | "hour" | "day" | "month" = "hour"
|
||||
period: "5minute" | "hour" | "day" | "month" = "hour",
|
||||
units?: StatisticsUnitConfiguration
|
||||
) =>
|
||||
hass.callWS<Statistics>({
|
||||
type: "recorder/statistics_during_period",
|
||||
@ -113,6 +131,7 @@ export const fetchStatistics = (
|
||||
end_time: endTime?.toISOString(),
|
||||
statistic_ids,
|
||||
period,
|
||||
units,
|
||||
});
|
||||
|
||||
export const validateStatistics = (hass: HomeAssistant) =>
|
||||
@ -204,13 +223,15 @@ export const adjustStatisticsSum = (
|
||||
hass: HomeAssistant,
|
||||
statistic_id: string,
|
||||
start_time: string,
|
||||
adjustment: number
|
||||
adjustment: number,
|
||||
display_unit: string
|
||||
): Promise<void> =>
|
||||
hass.callWS({
|
||||
type: "recorder/adjust_sum_statistics",
|
||||
statistic_id,
|
||||
start_time,
|
||||
adjustment,
|
||||
display_unit,
|
||||
});
|
||||
|
||||
export const getStatisticLabel = (
|
||||
|
@ -305,7 +305,8 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
|
||||
this.hass,
|
||||
this._params!.statistic.statistic_id,
|
||||
this._chosenStat!.start,
|
||||
this._amount! - this._origAmount!
|
||||
this._amount! - this._origAmount!,
|
||||
this._params!.statistic.display_unit_of_measurement
|
||||
);
|
||||
} catch (err: any) {
|
||||
this._busy = false;
|
||||
|
@ -27,6 +27,7 @@ import {
|
||||
fetchStatistics,
|
||||
getStatisticLabel,
|
||||
Statistics,
|
||||
StatisticsUnitConfiguration,
|
||||
} from "../../../../data/recorder";
|
||||
import { FrontendLocaleData } from "../../../../data/translation";
|
||||
import { SubscribeMixin } from "../../../../mixins/subscribe-mixin";
|
||||
@ -181,12 +182,19 @@ export class HuiEnergyDevicesGraphCard
|
||||
|
||||
const startMinHour = addHours(energyData.start, -1);
|
||||
|
||||
const lengthUnit = this.hass.config.unit_system.length || "";
|
||||
const units: StatisticsUnitConfiguration = {
|
||||
energy: "kWh",
|
||||
volume: lengthUnit === "km" ? "m³" : "ft³",
|
||||
};
|
||||
|
||||
const data = await fetchStatistics(
|
||||
this.hass,
|
||||
startMinHour,
|
||||
energyData.end,
|
||||
devices,
|
||||
period
|
||||
period,
|
||||
units
|
||||
);
|
||||
|
||||
Object.values(data).forEach((stat) => {
|
||||
@ -211,7 +219,8 @@ export class HuiEnergyDevicesGraphCard
|
||||
startCompareMinHour,
|
||||
energyData.endCompare,
|
||||
devices,
|
||||
period
|
||||
period,
|
||||
units
|
||||
);
|
||||
|
||||
Object.values(compareData).forEach((stat) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user