diff --git a/src/panels/config/energy/dialogs/dialog-energy-gas-settings.ts b/src/panels/config/energy/dialogs/dialog-energy-gas-settings.ts index 102c6ab5b7..595ec1c942 100644 --- a/src/panels/config/energy/dialogs/dialog-energy-gas-settings.ts +++ b/src/panels/config/energy/dialogs/dialog-energy-gas-settings.ts @@ -34,6 +34,8 @@ export class DialogEnergyGasSettings @state() private _costs?: "no-costs" | "number" | "entity" | "statistic"; + @state() private _unit?: string; + @state() private _error?: string; public async showDialog( @@ -55,6 +57,7 @@ export class DialogEnergyGasSettings public closeDialog(): void { this._params = undefined; this._source = undefined; + this._unit = undefined; this._error = undefined; fireEvent(this, "dialog-closed", { dialog: this.localName }); } @@ -64,6 +67,14 @@ export class DialogEnergyGasSettings return html``; } + const unit = + this._unit || + (this._params.unit === undefined + ? "m³ or kWh" + : this._params.unit === "energy" + ? "kWh" + : "m³"); + return html` ` @@ -174,7 +186,8 @@ export class DialogEnergyGasSettings ${this._costs === "number" ? html` - ${this.hass.localize( - `ui.panel.config.energy.gas.dialog.cost_number_suffix`, - { currency: this.hass.config.currency } - )} + ${this.hass.config.currency}/${unit} ` : ""} @@ -239,6 +247,18 @@ export class DialogEnergyGasSettings } private _statisticChanged(ev: CustomEvent<{ value: string }>) { + if (ev.detail.value) { + const entity = this.hass.states[ev.detail.value]; + if (entity?.attributes.unit_of_measurement) { + // Wh is normalized to kWh by stats generation + this._unit = + entity.attributes.unit_of_measurement === "Wh" + ? "kWh" + : entity.attributes.unit_of_measurement; + } + } else { + this._unit = undefined; + } this._source = { ...this._source!, stat_energy_from: ev.detail.value, diff --git a/src/translations/en.json b/src/translations/en.json index 1ee18be54a..3fb886faf8 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -1045,10 +1045,9 @@ "cost_stat": "Use an entity tracking the total costs", "cost_stat_input": "Total Costs Entity", "cost_entity": "Use an entity with current price", - "cost_entity_input": "Entity with the current price", + "cost_entity_input": "Entity with the current price per {unit}", "cost_number": "Use a static price", - "cost_number_input": "Price per m³", - "cost_number_suffix": "{currency}/m³" + "cost_number_input": "Price per {unit}" } }, "device_consumption": {