From 099ea61a944966f416e4fd4a711c3ebb11141c21 Mon Sep 17 00:00:00 2001 From: Cody C <50791984+codyc1515@users.noreply.github.com> Date: Tue, 14 May 2024 06:57:37 +1200 Subject: [PATCH] Add checks to energy dashboard for when preferences are empty (#19765) * Forbid completing energy dashboard setup unless at least one statistic is selected * If energy setup was completed but there are no sources available, start setup wizard again --- .../energy/cards/energy-setup-wizard-card.ts | 15 +++++++++++++++ .../energy/strategies/energy-view-strategy.ts | 8 ++++++++ src/translations/en.json | 4 +++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/panels/energy/cards/energy-setup-wizard-card.ts b/src/panels/energy/cards/energy-setup-wizard-card.ts index a68b1b34382b..87359e4250e3 100644 --- a/src/panels/energy/cards/energy-setup-wizard-card.ts +++ b/src/panels/energy/cards/energy-setup-wizard-card.ts @@ -137,6 +137,21 @@ 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: this.hass.localize( + "ui.panel.energy.setup.no_statistics_selected_title" + ), + text: this.hass.localize( + "ui.panel.energy.setup.no_statistics_selected_description" + ), + }); + return; + } try { this._preferences = await saveEnergyPreferences( this.hass, diff --git a/src/panels/energy/strategies/energy-view-strategy.ts b/src/panels/energy/strategies/energy-view-strategy.ts index 8fd05b04128f..7bec1c985bfb 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( 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",