From f717e51fbe22b23ad8fdb8a91af3a0635d4dd29a Mon Sep 17 00:00:00 2001 From: codyc1515 <50791984+codyc1515@users.noreply.github.com> Date: Sat, 10 Feb 2024 09:11:36 +0000 Subject: [PATCH 1/3] Forbid completing energy dashboard setup unless at least one statistic is selected --- src/panels/energy/cards/energy-setup-wizard-card.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/panels/energy/cards/energy-setup-wizard-card.ts b/src/panels/energy/cards/energy-setup-wizard-card.ts index a68b1b34382b..4bb54eaa704d 100644 --- a/src/panels/energy/cards/energy-setup-wizard-card.ts +++ b/src/panels/energy/cards/energy-setup-wizard-card.ts @@ -137,6 +137,17 @@ export class EnergySetupWizard extends LitElement implements LovelaceCard { if (!this._preferences) { return; } + // User made no selections during setup + if ( + this._preferences!.device_consumption.length === 0 && + this._preferences!.energy_sources.length === 0 + ) { + showAlertDialog(this, { + title: `No statistics selected`, + text: `You must select at least one statistic to finish setting up your Energy dashboard.`, + }); + return; + } try { this._preferences = await saveEnergyPreferences( this.hass, From fac88238febcba991503090e013adc58b49b70ee Mon Sep 17 00:00:00 2001 From: codyc1515 <50791984+codyc1515@users.noreply.github.com> Date: Sat, 10 Feb 2024 09:13:32 +0000 Subject: [PATCH 2/3] If energy setup was completed but there are no sources available, start setup wizard again --- src/panels/energy/strategies/energy-view-strategy.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/panels/energy/strategies/energy-view-strategy.ts b/src/panels/energy/strategies/energy-view-strategy.ts index 27a0a9137184..2b780cfacf6f 100644 --- a/src/panels/energy/strategies/energy-view-strategy.ts +++ b/src/panels/energy/strategies/energy-view-strategy.ts @@ -44,6 +44,14 @@ export class EnergyViewStrategy extends ReactiveElement { return view; } + // No energy sources available, start from scratch + if ( + prefs!.device_consumption.length === 0 && + prefs!.energy_sources.length === 0 + ) { + return setupWizard(); + } + view.type = "sidebar"; const hasGrid = prefs.energy_sources.find( From 84f82a8e2df8d095cfb3b470b7570558bf920b64 Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Mon, 13 May 2024 19:50:49 +0200 Subject: [PATCH 3/3] Localize message --- src/panels/energy/cards/energy-setup-wizard-card.ts | 12 ++++++++---- src/translations/en.json | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/panels/energy/cards/energy-setup-wizard-card.ts b/src/panels/energy/cards/energy-setup-wizard-card.ts index 4bb54eaa704d..87359e4250e3 100644 --- a/src/panels/energy/cards/energy-setup-wizard-card.ts +++ b/src/panels/energy/cards/energy-setup-wizard-card.ts @@ -139,12 +139,16 @@ export class EnergySetupWizard extends LitElement implements LovelaceCard { } // User made no selections during setup if ( - this._preferences!.device_consumption.length === 0 && - this._preferences!.energy_sources.length === 0 + this._preferences.device_consumption.length === 0 && + this._preferences.energy_sources.length === 0 ) { showAlertDialog(this, { - title: `No statistics selected`, - text: `You must select at least one statistic to finish setting up your Energy dashboard.`, + title: this.hass.localize( + "ui.panel.energy.setup.no_statistics_selected_title" + ), + text: this.hass.localize( + "ui.panel.energy.setup.no_statistics_selected_description" + ), }); return; } diff --git a/src/translations/en.json b/src/translations/en.json index eab739b2f0e1..f08e410c6027 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -6929,7 +6929,9 @@ "next": "Next", "back": "Back", "done": "Show me my energy dashboard!", - "step": "Step {step} of {steps}" + "step": "Step {step} of {steps}", + "no_statistics_selected_title": "No statistics selected", + "no_statistics_selected_description": "You must select at least one statistic to finish setting up your Energy dashboard." }, "charts": { "stat_house_energy_meter": "Total energy consumption",