mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-25 05:47:20 +00:00
Use currency from core config (#9628)
This commit is contained in:
parent
8cd9f891fb
commit
1d7007584c
@ -85,7 +85,6 @@ type EnergySource =
|
||||
| GridSourceTypeEnergyPreference;
|
||||
|
||||
export interface EnergyPreferences {
|
||||
currency: string;
|
||||
energy_sources: EnergySource[];
|
||||
device_consumption: DeviceConsumptionEnergyPreference[];
|
||||
}
|
||||
|
@ -201,7 +201,6 @@ export class EnergyGridSettings extends LitElement {
|
||||
|
||||
private _addFromSource() {
|
||||
showEnergySettingsGridFlowFromDialog(this, {
|
||||
currency: this.preferences.currency,
|
||||
saveCallback: async (flow) => {
|
||||
let preferences: EnergyPreferences;
|
||||
const gridSource = this.preferences.energy_sources.find(
|
||||
@ -236,7 +235,6 @@ export class EnergyGridSettings extends LitElement {
|
||||
|
||||
private _addToSource() {
|
||||
showEnergySettingsGridFlowToDialog(this, {
|
||||
currency: this.preferences.currency,
|
||||
saveCallback: async (flow) => {
|
||||
let preferences: EnergyPreferences;
|
||||
const gridSource = this.preferences.energy_sources.find(
|
||||
@ -273,7 +271,6 @@ export class EnergyGridSettings extends LitElement {
|
||||
const origSource: FlowFromGridSourceEnergyPreference =
|
||||
ev.currentTarget.closest(".row").source;
|
||||
showEnergySettingsGridFlowFromDialog(this, {
|
||||
currency: this.preferences.currency,
|
||||
source: { ...origSource },
|
||||
saveCallback: async (source) => {
|
||||
const flowFrom = energySourcesByType(this.preferences).grid![0]
|
||||
@ -301,7 +298,6 @@ export class EnergyGridSettings extends LitElement {
|
||||
const origSource: FlowToGridSourceEnergyPreference =
|
||||
ev.currentTarget.closest(".row").source;
|
||||
showEnergySettingsGridFlowToDialog(this, {
|
||||
currency: this.preferences.currency,
|
||||
source: { ...origSource },
|
||||
saveCallback: async (source) => {
|
||||
const flowTo = energySourcesByType(this.preferences).grid![0].flow_to;
|
||||
|
@ -203,7 +203,7 @@ export class DialogEnergyGridFlowSettings
|
||||
<span slot="suffix"
|
||||
>${this.hass.localize(
|
||||
`ui.panel.config.energy.grid.flow_dialog.${this._params.direction}.cost_number_suffix`,
|
||||
{ currency: this._params.currency }
|
||||
{ currency: this.hass.config.currency }
|
||||
)}</span
|
||||
>
|
||||
</paper-input>`
|
||||
|
@ -10,7 +10,6 @@ export interface EnergySettingsGridFlowDialogParams {
|
||||
source?:
|
||||
| FlowFromGridSourceEnergyPreference
|
||||
| FlowToGridSourceEnergyPreference;
|
||||
currency: string;
|
||||
direction: "from" | "to";
|
||||
saveCallback: (
|
||||
source:
|
||||
@ -21,13 +20,11 @@ export interface EnergySettingsGridFlowDialogParams {
|
||||
|
||||
export interface EnergySettingsGridFlowFromDialogParams {
|
||||
source?: FlowFromGridSourceEnergyPreference;
|
||||
currency: string;
|
||||
saveCallback: (source: FlowFromGridSourceEnergyPreference) => Promise<void>;
|
||||
}
|
||||
|
||||
export interface EnergySettingsGridFlowToDialogParams {
|
||||
source?: FlowToGridSourceEnergyPreference;
|
||||
currency: string;
|
||||
saveCallback: (source: FlowToGridSourceEnergyPreference) => Promise<void>;
|
||||
}
|
||||
|
||||
|
@ -1,22 +1,15 @@
|
||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
|
||||
import "../../../components/ha-svg-icon";
|
||||
import {
|
||||
EnergyPreferences,
|
||||
getEnergyPreferences,
|
||||
saveEnergyPreferences,
|
||||
} from "../../../data/energy";
|
||||
|
||||
import { EnergyPreferences, getEnergyPreferences } from "../../../data/energy";
|
||||
import "../../../layouts/hass-loading-screen";
|
||||
import "../../../layouts/hass-tabs-subpage";
|
||||
import { haStyle } from "../../../resources/styles";
|
||||
import type { HomeAssistant, Route } from "../../../types";
|
||||
import { configSections } from "../ha-panel-config";
|
||||
import "./components/ha-energy-device-settings";
|
||||
import "./components/ha-energy-grid-settings";
|
||||
import "./components/ha-energy-solar-settings";
|
||||
import "./components/ha-energy-device-settings";
|
||||
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||
|
||||
const INITIAL_CONFIG = {
|
||||
currency: "€",
|
||||
@ -72,18 +65,6 @@ class HaConfigEnergy extends LitElement {
|
||||
.route=${this.route}
|
||||
.tabs=${configSections.experiences}
|
||||
>
|
||||
<ha-card .header=${"General energy settings"}>
|
||||
<div class="card-content">
|
||||
<paper-input
|
||||
.label=${"Currency"}
|
||||
.value=${this._preferences!.currency}
|
||||
@value-changed=${this._currencyChanged}
|
||||
>
|
||||
</paper-input>
|
||||
|
||||
<mwc-button @click=${this._save}>Save</mwc-button>
|
||||
</div>
|
||||
</ha-card>
|
||||
<div class="container">
|
||||
<ha-energy-grid-settings
|
||||
.hass=${this.hass}
|
||||
@ -105,24 +86,6 @@ class HaConfigEnergy extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
private _currencyChanged(ev: CustomEvent) {
|
||||
this._preferences!.currency = ev.detail.value;
|
||||
}
|
||||
|
||||
private async _save() {
|
||||
if (!this._preferences) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this._preferences = await saveEnergyPreferences(
|
||||
this.hass,
|
||||
this._preferences
|
||||
);
|
||||
} catch (err) {
|
||||
showAlertDialog(this, { title: `Failed to save config: ${err.message}` });
|
||||
}
|
||||
}
|
||||
|
||||
private async _fetchConfig() {
|
||||
try {
|
||||
this._preferences = await getEnergyPreferences(this.hass);
|
||||
|
@ -21,7 +21,6 @@ export class EnergySetupWizard extends LitElement implements LovelaceCard {
|
||||
@state() private _step = 0;
|
||||
|
||||
@state() private _preferences: EnergyPreferences = {
|
||||
currency: "€",
|
||||
energy_sources: [],
|
||||
device_consumption: [],
|
||||
};
|
||||
|
@ -11,6 +11,7 @@ import {
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { computeStateName } from "../../../../common/entity/compute_state_name";
|
||||
import { round } from "../../../../common/number/round";
|
||||
import { formatNumber } from "../../../../common/string/format_number";
|
||||
import "../../../../components/chart/statistics-chart";
|
||||
import "../../../../components/ha-card";
|
||||
import {
|
||||
@ -131,7 +132,10 @@ export class HuiEnergyCostsTableCard
|
||||
<td
|
||||
class="mdc-data-table__cell mdc-data-table__cell--numeric"
|
||||
>
|
||||
${this._config!.prefs.currency} ${cost.toFixed(2)}
|
||||
${formatNumber(cost, this.hass.locale, {
|
||||
style: "currency",
|
||||
currency: this.hass.config.currency!,
|
||||
})}
|
||||
</td>
|
||||
</tr>`;
|
||||
})}
|
||||
@ -162,7 +166,10 @@ export class HuiEnergyCostsTableCard
|
||||
<td
|
||||
class="mdc-data-table__cell mdc-data-table__cell--numeric"
|
||||
>
|
||||
${this._config!.prefs.currency} ${cost.toFixed(2)}
|
||||
${formatNumber(cost, this.hass.locale, {
|
||||
style: "currency",
|
||||
currency: this.hass.config.currency!,
|
||||
})}
|
||||
</td>
|
||||
</tr>`;
|
||||
})}
|
||||
@ -172,7 +179,10 @@ export class HuiEnergyCostsTableCard
|
||||
${round(totalEnergy)} kWh
|
||||
</td>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">
|
||||
${this._config!.prefs.currency} ${totalCost.toFixed(2)}
|
||||
${formatNumber(totalCost, this.hass.locale, {
|
||||
style: "currency",
|
||||
currency: this.hass.config.currency!,
|
||||
})}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -171,7 +171,7 @@ class HuiEnergySummaryCard extends LitElement implements LovelaceCard {
|
||||
types
|
||||
.grid![0].flow_from.map((flow) => flow.stat_cost)
|
||||
.filter(Boolean) as string[],
|
||||
prefs.currency
|
||||
this.hass.config.currency!
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user