1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-24 20:55:49 +00:00

Handle lovelace to home redirect

This commit is contained in:
Paul Bottein
2025-12-08 18:21:37 +01:00
parent 0cacc535ca
commit bb0c14cc57
4 changed files with 18 additions and 53 deletions

View File

@@ -56,6 +56,8 @@ export class HassRouterPage extends ReactiveElement {
private _initialLoadDone = false;
private _showLoadingScreenTimeout?: number;
private _computeTail = memoizeOne((route: Route) => {
const dividerPos = route.path.indexOf("/", 1);
return dividerPos === -1
@@ -153,7 +155,11 @@ export class HassRouterPage extends ReactiveElement {
? routeOptions.load()
: Promise.resolve();
let showLoadingScreenTimeout: undefined | number;
// Clear any existing loading screen timeout from previous navigation
if (this._showLoadingScreenTimeout) {
clearTimeout(this._showLoadingScreenTimeout);
this._showLoadingScreenTimeout = undefined;
}
// Check when loading the page source failed.
loadProm.catch((err) => {
@@ -170,8 +176,9 @@ export class HassRouterPage extends ReactiveElement {
this.removeChild(this.lastChild!);
}
if (showLoadingScreenTimeout) {
clearTimeout(showLoadingScreenTimeout);
if (this._showLoadingScreenTimeout) {
clearTimeout(this._showLoadingScreenTimeout);
this._showLoadingScreenTimeout = undefined;
}
// Show error screen
@@ -191,7 +198,7 @@ export class HassRouterPage extends ReactiveElement {
// That way we won't have a double fast flash on fast connections.
let created = false;
showLoadingScreenTimeout = window.setTimeout(() => {
this._showLoadingScreenTimeout = window.setTimeout(() => {
if (created || this._currentPage !== newPage) {
return;
}

View File

@@ -7,7 +7,7 @@ import type { PropertyValues } from "lit";
import { customElement, property } from "lit/decorators";
import { deepActiveElement } from "../common/dom/deep-active-element";
import { deepEqual } from "../common/util/deep-equal";
import { DEFAULT_PANEL, getDefaultPanel } from "../data/panel";
import { getDefaultPanel } from "../data/panel";
import type { CustomPanelInfo } from "../data/panel_custom";
import type { HomeAssistant, Panels } from "../types";
import { removeLaunchScreen } from "../util/launch-screen";
@@ -132,10 +132,6 @@ class PartialPanelResolver extends HassRouterPage {
return {
beforeRender: (page) => {
if (!page || !routes[page]) {
// Special case: redirect /lovelace to /home when lovelace panel doesn't exist
if (page === "lovelace") {
return DEFAULT_PANEL;
}
return getDefaultPanel(this.hass).url_path;
}
return undefined;

View File

@@ -30,7 +30,6 @@ import "../../../../components/ha-md-list-item";
import "../../../../components/ha-svg-icon";
import "../../../../components/ha-tooltip";
import { saveFrontendSystemData } from "../../../../data/frontend";
import type { LovelacePanelConfig } from "../../../../data/lovelace";
import type { LovelaceRawConfig } from "../../../../data/lovelace/config/types";
import {
isStrategyDashboard,
@@ -306,23 +305,7 @@ export class HaConfigLovelaceDashboards extends LitElement {
private _getItems = memoize(
(dashboards: LovelaceDashboard[], defaultUrlPath: string | null) => {
const mode = (this.hass.panels?.lovelace?.config as LovelacePanelConfig)
.mode;
const isDefault = defaultUrlPath === "lovelace";
const result: DataTableItem[] = [
{
icon: "mdi:view-dashboard",
title: this.hass.localize("panel.states"),
default: isDefault,
show_in_sidebar: true,
require_admin: false,
url_path: "lovelace",
mode: mode,
filename: mode === "yaml" ? "ui-lovelace.yaml" : "",
type: "built_in",
localized_type: this._localizeType("built_in"),
},
];
const result: DataTableItem[] = [];
PANEL_DASHBOARDS.forEach((panel) => {
const panelInfo = this.hass.panels[panel];

View File

@@ -3,6 +3,7 @@ import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import type { PropertyValues, TemplateResult } from "lit";
import { html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
import { navigate } from "../../common/navigate";
import { constructUrlCurrentPath } from "../../common/url/construct-url";
import {
addSearchParam,
@@ -10,6 +11,7 @@ import {
} from "../../common/url/search-params";
import { debounce } from "../../common/util/debounce";
import { deepEqual } from "../../common/util/deep-equal";
import "../../components/ha-button";
import { domainToName } from "../../data/integration";
import { subscribeLovelaceUpdates } from "../../data/lovelace";
import type {
@@ -34,7 +36,6 @@ import { checkLovelaceConfig } from "./common/check-lovelace-config";
import { loadLovelaceResources } from "./common/load-resources";
import { showSaveDialog } from "./editor/show-save-config-dialog";
import "./hui-root";
import "../../components/ha-button";
import { generateLovelaceDashboardStrategy } from "./strategies/get-strategy";
import type { Lovelace } from "./types";
@@ -97,11 +98,6 @@ export class LovelacePanel extends LitElement {
this.lovelace.rawConfig,
this.lovelace.mode
);
} else if (this.lovelace && this.lovelace.mode === "generated") {
// When lovelace is generated, we re-generate each time a user goes
// to the states panel to make sure new entities are shown.
this._panelState = "loading";
this._regenerateConfig();
} else if (this._fetchConfigOnConnect) {
// Config was changed when we were not at the lovelace panel
this._fetchConfig(false);
@@ -296,15 +292,6 @@ export class LovelacePanel extends LitElement {
}
};
private async _regenerateConfig() {
const conf = await generateLovelaceDashboardStrategy(
DEFAULT_CONFIG,
this.hass!
);
this._setLovelaceConfig(conf, DEFAULT_CONFIG, "generated");
this._panelState = "loaded";
}
private async _subscribeUpdates() {
this._unsubUpdates = subscribeLovelaceUpdates(
this.hass!.connection,
@@ -352,7 +339,7 @@ export class LovelacePanel extends LitElement {
let conf: LovelaceConfig;
let rawConf: LovelaceRawConfig | undefined;
let confMode: Lovelace["mode"] = this.panel!.config.mode;
const confMode: Lovelace["mode"] = this.panel!.config.mode;
let confProm: Promise<LovelaceRawConfig> | undefined;
const preloadWindow = window as WindowWithPreloads;
@@ -404,16 +391,8 @@ export class LovelacePanel extends LitElement {
this._errorMsg = err.message;
return;
}
if (!this.hass?.entities || !this.hass.devices || !this.hass.areas) {
// We need these to generate a dashboard, wait for them
return;
}
conf = await generateLovelaceDashboardStrategy(
DEFAULT_CONFIG,
this.hass!
);
rawConf = DEFAULT_CONFIG;
confMode = "generated";
navigate("/home");
return;
} finally {
this._loading = false;
// Ignore updates for another 2 seconds.