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