mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 02:06:42 +00:00
Show correct units for prices in energy gas settings (#10164)
This commit is contained in:
parent
365cf1f7ef
commit
8e010618bb
@ -34,6 +34,8 @@ export class DialogEnergyGasSettings
|
|||||||
|
|
||||||
@state() private _costs?: "no-costs" | "number" | "entity" | "statistic";
|
@state() private _costs?: "no-costs" | "number" | "entity" | "statistic";
|
||||||
|
|
||||||
|
@state() private _unit?: string;
|
||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
public async showDialog(
|
public async showDialog(
|
||||||
@ -55,6 +57,7 @@ export class DialogEnergyGasSettings
|
|||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
this._source = undefined;
|
this._source = undefined;
|
||||||
|
this._unit = undefined;
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
@ -64,6 +67,14 @@ export class DialogEnergyGasSettings
|
|||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unit =
|
||||||
|
this._unit ||
|
||||||
|
(this._params.unit === undefined
|
||||||
|
? "m³ or kWh"
|
||||||
|
: this._params.unit === "energy"
|
||||||
|
? "kWh"
|
||||||
|
: "m³");
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-dialog
|
<ha-dialog
|
||||||
open
|
open
|
||||||
@ -154,7 +165,8 @@ export class DialogEnergyGasSettings
|
|||||||
include-domains='["sensor", "input_number"]'
|
include-domains='["sensor", "input_number"]'
|
||||||
.value=${this._source.entity_energy_price}
|
.value=${this._source.entity_energy_price}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
`ui.panel.config.energy.gas.dialog.cost_entity_input`
|
`ui.panel.config.energy.gas.dialog.cost_entity_input`,
|
||||||
|
{ unit }
|
||||||
)}
|
)}
|
||||||
@value-changed=${this._priceEntityChanged}
|
@value-changed=${this._priceEntityChanged}
|
||||||
></ha-entity-picker>`
|
></ha-entity-picker>`
|
||||||
@ -174,7 +186,8 @@ export class DialogEnergyGasSettings
|
|||||||
${this._costs === "number"
|
${this._costs === "number"
|
||||||
? html`<paper-input
|
? html`<paper-input
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
`ui.panel.config.energy.gas.dialog.cost_number_input`
|
`ui.panel.config.energy.gas.dialog.cost_number_input`,
|
||||||
|
{ unit }
|
||||||
)}
|
)}
|
||||||
no-label-float
|
no-label-float
|
||||||
class="price-options"
|
class="price-options"
|
||||||
@ -183,12 +196,7 @@ export class DialogEnergyGasSettings
|
|||||||
.value=${this._source.number_energy_price}
|
.value=${this._source.number_energy_price}
|
||||||
@value-changed=${this._numberPriceChanged}
|
@value-changed=${this._numberPriceChanged}
|
||||||
>
|
>
|
||||||
<span slot="suffix"
|
<span slot="suffix">${this.hass.config.currency}/${unit}</span>
|
||||||
>${this.hass.localize(
|
|
||||||
`ui.panel.config.energy.gas.dialog.cost_number_suffix`,
|
|
||||||
{ currency: this.hass.config.currency }
|
|
||||||
)}</span
|
|
||||||
>
|
|
||||||
</paper-input>`
|
</paper-input>`
|
||||||
: ""}
|
: ""}
|
||||||
|
|
||||||
@ -239,6 +247,18 @@ export class DialogEnergyGasSettings
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _statisticChanged(ev: CustomEvent<{ value: string }>) {
|
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 = {
|
||||||
...this._source!,
|
...this._source!,
|
||||||
stat_energy_from: ev.detail.value,
|
stat_energy_from: ev.detail.value,
|
||||||
|
@ -1045,10 +1045,9 @@
|
|||||||
"cost_stat": "Use an entity tracking the total costs",
|
"cost_stat": "Use an entity tracking the total costs",
|
||||||
"cost_stat_input": "Total Costs Entity",
|
"cost_stat_input": "Total Costs Entity",
|
||||||
"cost_entity": "Use an entity with current price",
|
"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": "Use a static price",
|
||||||
"cost_number_input": "Price per m³",
|
"cost_number_input": "Price per {unit}"
|
||||||
"cost_number_suffix": "{currency}/m³"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"device_consumption": {
|
"device_consumption": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user