Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix costs in energy csv download #23322

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 45 additions & 16 deletions src/panels/energy/ha-panel-energy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,46 +204,59 @@ class PanelEnergy extends LitElement {
type: string,
statIds: string[],
unit: string,
costType?: string
costType?: string,
costStatIds?: string[]
) {
if (statIds.length) {
statIds.forEach((stat) => processStat(stat, type, unit));
if (costType) {
statIds.forEach((stat) => {
const costStat = energyData.state.info.cost_sensors[stat];
if (energyData.state.info.cost_sensors[stat]) {
processStat(costStat, costType, currency);
}
});
if (costType && costStatIds) {
costStatIds.forEach((stat) => processStat(stat, costType, currency));
}
}
};

const grid_consumptions: string[] = [];
const grid_productions: string[] = [];
const grid_consumptions_cost: string[] = [];
const grid_productions_cost: string[] = [];
energy_sources
.filter((s) => s.type === "grid")
.forEach((source) => {
source = source as GridSourceTypeEnergyPreference;
source.flow_from.forEach((flowFrom) => {
grid_consumptions.push(flowFrom.stat_energy_from);
const statId = flowFrom.stat_energy_from;
grid_consumptions.push(statId);
const costId =
flowFrom.stat_cost || energyData.state.info.cost_sensors[statId];
if (costId) {
grid_consumptions_cost.push(costId);
}
});
source.flow_to.forEach((flowTo) => {
grid_productions.push(flowTo.stat_energy_to);
const statId = flowTo.stat_energy_to;
grid_productions.push(statId);
const costId =
flowTo.stat_compensation ||
energyData.state.info.cost_sensors[statId];
if (costId) {
grid_productions_cost.push(costId);
}
});
});

printCategory(
"grid_consumption",
grid_consumptions,
electricUnit,
"grid_consumption_cost"
"grid_consumption_cost",
grid_consumptions_cost
);
printCategory(
"grid_return",
grid_productions,
electricUnit,
"grid_return_compensation"
"grid_return_compensation",
grid_productions_cost
);

const battery_ins: string[] = [];
Expand All @@ -270,33 +283,49 @@ class PanelEnergy extends LitElement {
printCategory("solar_production", solar_productions, electricUnit);

const gas_consumptions: string[] = [];
const gas_consumptions_cost: string[] = [];
energy_sources
.filter((s) => s.type === "gas")
.forEach((source) => {
source = source as GasSourceTypeEnergyPreference;
gas_consumptions.push(source.stat_energy_from);
const statId = source.stat_energy_from;
gas_consumptions.push(statId);
const costId =
source.stat_cost || energyData.state.info.cost_sensors[statId];
if (costId) {
gas_consumptions_cost.push(costId);
}
});

printCategory(
"gas_consumption",
gas_consumptions,
gasUnit,
"gas_consumption_cost"
"gas_consumption_cost",
gas_consumptions_cost
);

const water_consumptions: string[] = [];
const water_consumptions_cost: string[] = [];
energy_sources
.filter((s) => s.type === "water")
.forEach((source) => {
source = source as WaterSourceTypeEnergyPreference;
water_consumptions.push(source.stat_energy_from);
const statId = source.stat_energy_from;
water_consumptions.push(statId);
const costId =
source.stat_cost || energyData.state.info.cost_sensors[statId];
if (costId) {
water_consumptions_cost.push(costId);
}
});

printCategory(
"water_consumption",
water_consumptions,
waterUnit,
"water_consumption_cost"
"water_consumption_cost",
water_consumptions_cost
);

const devices: string[] = [];
Expand Down
Loading