Skip to content

Commit 19a4e37

Browse files
authored
Fix incorrect unit displayed in energy grid flow settings (#27822)
1 parent 76514ba commit 19a4e37

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

src/panels/config/energy/dialogs/dialog-energy-grid-flow-settings.ts

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "../../../../components/ha-dialog";
99
import "../../../../components/ha-button";
1010
import "../../../../components/ha-formfield";
1111
import "../../../../components/ha-radio";
12+
import "../../../../components/ha-markdown";
1213
import type { HaRadio } from "../../../../components/ha-radio";
1314
import type {
1415
FlowFromGridSourceEnergyPreference,
@@ -19,11 +20,7 @@ import {
1920
emptyFlowToGridSourceEnergyPreference,
2021
energyStatisticHelpUrl,
2122
} from "../../../../data/energy";
22-
import {
23-
getDisplayUnit,
24-
getStatisticMetadata,
25-
isExternalStatistic,
26-
} from "../../../../data/recorder";
23+
import { isExternalStatistic } from "../../../../data/recorder";
2724
import { getSensorDeviceClassConvertibleUnits } from "../../../../data/sensor";
2825
import type { HassDialog } from "../../../../dialogs/make-dialog-manager";
2926
import { haStyleDialog } from "../../../../resources/styles";
@@ -47,8 +44,6 @@ export class DialogEnergyGridFlowSettings
4744

4845
@state() private _costs?: "no-costs" | "number" | "entity" | "statistic";
4946

50-
@state() private _pickedDisplayUnit?: string | null;
51-
5247
@state() private _energy_units?: string[];
5348

5449
@state() private _error?: string;
@@ -81,11 +76,6 @@ export class DialogEnergyGridFlowSettings
8176
: "stat_energy_to"
8277
];
8378

84-
this._pickedDisplayUnit = getDisplayUnit(
85-
this.hass,
86-
initialSourceId,
87-
params.metadata
88-
);
8979
this._energy_units = (
9080
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
9181
).units;
@@ -103,7 +93,6 @@ export class DialogEnergyGridFlowSettings
10393
public closeDialog() {
10494
this._params = undefined;
10595
this._source = undefined;
106-
this._pickedDisplayUnit = undefined;
10796
this._error = undefined;
10897
this._excludeList = undefined;
10998
fireEvent(this, "dialog-closed", { dialog: this.localName });
@@ -117,10 +106,6 @@ export class DialogEnergyGridFlowSettings
117106

118107
const pickableUnit = this._energy_units?.join(", ") || "";
119108

120-
const unitPriceSensor = this._pickedDisplayUnit
121-
? `${this.hass.config.currency}/${this._pickedDisplayUnit}`
122-
: undefined;
123-
124109
const unitPriceFixed = `${this.hass.config.currency}/kWh`;
125110

126111
const externalSource =
@@ -246,9 +231,15 @@ export class DialogEnergyGridFlowSettings
246231
.hass=${this.hass}
247232
include-domains='["sensor", "input_number"]'
248233
.value=${this._source.entity_energy_price}
249-
.label=${`${this.hass.localize(
234+
.label=${this.hass.localize(
250235
`ui.panel.config.energy.grid.flow_dialog.${this._params.direction}.cost_entity_input`
251-
)} ${unitPriceSensor ? ` (${unitPriceSensor})` : ""}`}
236+
)}
237+
.helper=${html`<ha-markdown
238+
.content=${this.hass.localize(
239+
"ui.panel.config.energy.grid.flow_dialog.cost_entity_helper",
240+
{ currency: this.hass.config.currency }
241+
)}
242+
></ha-markdown>`}
252243
@value-changed=${this._priceEntityChanged}
253244
></ha-entity-picker>`
254245
: ""}
@@ -341,16 +332,6 @@ export class DialogEnergyGridFlowSettings
341332
}
342333

343334
private async _statisticChanged(ev: CustomEvent<{ value: string }>) {
344-
if (ev.detail.value) {
345-
const metadata = await getStatisticMetadata(this.hass, [ev.detail.value]);
346-
this._pickedDisplayUnit = getDisplayUnit(
347-
this.hass,
348-
ev.detail.value,
349-
metadata[0]
350-
);
351-
} else {
352-
this._pickedDisplayUnit = undefined;
353-
}
354335
this._source = {
355336
...this._source!,
356337
[this._params!.direction === "from"

src/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,6 +3071,7 @@
30713071
"remove_co2_signal": "Remove Electricity Maps integration",
30723072
"add_co2_signal": "Add Electricity Maps integration",
30733073
"flow_dialog": {
3074+
"cost_entity_helper": "Any sensor with a unit of `{currency}/(valid energy unit)` (e.g. `{currency}/Wh` or `{currency}/kWh`) may be used and will be automatically converted.",
30743075
"from": {
30753076
"header": "Configure grid consumption",
30763077
"paragraph": "Grid consumption is the energy that flows from the energy grid to your home.",

0 commit comments

Comments
 (0)