Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks to energy dashboard for when preferences are empty #19765

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/panels/energy/cards/energy-setup-wizard-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
silamon marked this conversation as resolved.
Show resolved Hide resolved
) {
showAlertDialog(this, {
title: `No statistics selected`,
text: `You must select at least one statistic to finish setting up your Energy dashboard.`,
silamon marked this conversation as resolved.
Show resolved Hide resolved
});
return;
}
try {
this._preferences = await saveEnergyPreferences(
this.hass,
Expand Down
8 changes: 8 additions & 0 deletions src/panels/energy/strategies/energy-view-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading