From 19a4e37933fc6d876fe0af5a62673295c2a4318d Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Wed, 5 Nov 2025 22:46:19 -0800 Subject: [PATCH] Fix incorrect unit displayed in energy grid flow settings (#27822) --- .../dialog-energy-grid-flow-settings.ts | 39 +++++-------------- src/translations/en.json | 1 + 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/panels/config/energy/dialogs/dialog-energy-grid-flow-settings.ts b/src/panels/config/energy/dialogs/dialog-energy-grid-flow-settings.ts index d0fddbc8ba..4bfbde0abf 100644 --- a/src/panels/config/energy/dialogs/dialog-energy-grid-flow-settings.ts +++ b/src/panels/config/energy/dialogs/dialog-energy-grid-flow-settings.ts @@ -9,6 +9,7 @@ import "../../../../components/ha-dialog"; import "../../../../components/ha-button"; import "../../../../components/ha-formfield"; import "../../../../components/ha-radio"; +import "../../../../components/ha-markdown"; import type { HaRadio } from "../../../../components/ha-radio"; import type { FlowFromGridSourceEnergyPreference, @@ -19,11 +20,7 @@ import { emptyFlowToGridSourceEnergyPreference, energyStatisticHelpUrl, } from "../../../../data/energy"; -import { - getDisplayUnit, - getStatisticMetadata, - isExternalStatistic, -} from "../../../../data/recorder"; +import { isExternalStatistic } from "../../../../data/recorder"; import { getSensorDeviceClassConvertibleUnits } from "../../../../data/sensor"; import type { HassDialog } from "../../../../dialogs/make-dialog-manager"; import { haStyleDialog } from "../../../../resources/styles"; @@ -47,8 +44,6 @@ export class DialogEnergyGridFlowSettings @state() private _costs?: "no-costs" | "number" | "entity" | "statistic"; - @state() private _pickedDisplayUnit?: string | null; - @state() private _energy_units?: string[]; @state() private _error?: string; @@ -81,11 +76,6 @@ export class DialogEnergyGridFlowSettings : "stat_energy_to" ]; - this._pickedDisplayUnit = getDisplayUnit( - this.hass, - initialSourceId, - params.metadata - ); this._energy_units = ( await getSensorDeviceClassConvertibleUnits(this.hass, "energy") ).units; @@ -103,7 +93,6 @@ export class DialogEnergyGridFlowSettings public closeDialog() { this._params = undefined; this._source = undefined; - this._pickedDisplayUnit = undefined; this._error = undefined; this._excludeList = undefined; fireEvent(this, "dialog-closed", { dialog: this.localName }); @@ -117,10 +106,6 @@ export class DialogEnergyGridFlowSettings const pickableUnit = this._energy_units?.join(", ") || ""; - const unitPriceSensor = this._pickedDisplayUnit - ? `${this.hass.config.currency}/${this._pickedDisplayUnit}` - : undefined; - const unitPriceFixed = `${this.hass.config.currency}/kWh`; const externalSource = @@ -246,9 +231,15 @@ export class DialogEnergyGridFlowSettings .hass=${this.hass} include-domains='["sensor", "input_number"]' .value=${this._source.entity_energy_price} - .label=${`${this.hass.localize( + .label=${this.hass.localize( `ui.panel.config.energy.grid.flow_dialog.${this._params.direction}.cost_entity_input` - )} ${unitPriceSensor ? ` (${unitPriceSensor})` : ""}`} + )} + .helper=${html``} @value-changed=${this._priceEntityChanged} >` : ""} @@ -341,16 +332,6 @@ export class DialogEnergyGridFlowSettings } private async _statisticChanged(ev: CustomEvent<{ value: string }>) { - if (ev.detail.value) { - const metadata = await getStatisticMetadata(this.hass, [ev.detail.value]); - this._pickedDisplayUnit = getDisplayUnit( - this.hass, - ev.detail.value, - metadata[0] - ); - } else { - this._pickedDisplayUnit = undefined; - } this._source = { ...this._source!, [this._params!.direction === "from" diff --git a/src/translations/en.json b/src/translations/en.json index 3672328c2d..ca0877753e 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3071,6 +3071,7 @@ "remove_co2_signal": "Remove Electricity Maps integration", "add_co2_signal": "Add Electricity Maps integration", "flow_dialog": { + "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.", "from": { "header": "Configure grid consumption", "paragraph": "Grid consumption is the energy that flows from the energy grid to your home.",