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