Compare commits

..

4 Commits

Author SHA1 Message Date
Paul Bottein
b44542c83c Rename special rules for lovelace dashboard 2025-12-09 17:49:07 +01:00
Paul Bottein
36518bbce7 Remove special url path for lovelace 2025-12-09 15:17:57 +01:00
Paul Bottein
bb0c14cc57 Handle lovelace to home redirect 2025-12-09 15:12:58 +01:00
Paul Bottein
0cacc535ca Set home as default dashboard 2025-12-09 15:12:58 +01:00
6 changed files with 31 additions and 75 deletions

View File

@@ -246,7 +246,7 @@ export class HaGenericPicker extends LitElement {
private _unknownValue = memoizeOne(
(value?: string, items?: (PickerComboBoxItem | string)[]) => {
if (value === undefined || value === null || value === "" || !items) {
if (value === undefined || !items) {
return false;
}

View File

@@ -8,12 +8,11 @@ import {
mdiLightningBolt,
mdiPlayBoxMultiple,
mdiTooltipAccount,
mdiViewDashboard,
} from "@mdi/js";
import type { HomeAssistant, PanelInfo } from "../types";
/** Panel to show when no panel is picked. */
export const DEFAULT_PANEL = "lovelace";
export const DEFAULT_PANEL = "home";
export const getLegacyDefaultPanelUrlPath = (): string | null => {
const defaultPanel = window.localStorage.getItem("defaultPanel");
@@ -33,10 +32,6 @@ export const getDefaultPanel = (hass: HomeAssistant): PanelInfo => {
};
export const getPanelNameTranslationKey = (panel: PanelInfo) => {
if (panel.url_path === "lovelace") {
return "panel.states" as const;
}
if (panel.url_path === "profile") {
return "panel.profile" as const;
}
@@ -77,8 +72,6 @@ export const getPanelIcon = (panel: PanelInfo): string | undefined => {
switch (panel.component_name) {
case "profile":
return "mdi:account";
case "lovelace":
return "mdi:view-dashboard";
}
}
@@ -91,9 +84,8 @@ export const PANEL_ICON_PATHS = {
energy: mdiLightningBolt,
history: mdiChartBox,
logbook: mdiFormatListBulletedType,
lovelace: mdiViewDashboard,
profile: mdiAccount,
map: mdiTooltipAccount,
profile: mdiAccount,
"media-browser": mdiPlayBoxMultiple,
todo: mdiClipboardList,
};

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

@@ -60,7 +60,6 @@ export class DialogLovelaceDashboardDetail extends LitElement {
}
const titleInvalid = !this._data.title || !this._data.title.trim();
const isLovelaceDashboard = this._params.urlPath === "lovelace";
return html`
<ha-dialog
@@ -85,20 +84,16 @@ export class DialogLovelaceDashboardDetail extends LitElement {
? this.hass.localize(
"ui.panel.config.lovelace.dashboards.cant_edit_yaml"
)
: isLovelaceDashboard
? this.hass.localize(
"ui.panel.config.lovelace.dashboards.cant_edit_lovelace"
)
: html`
<ha-form
.schema=${this._schema(this._params)}
.data=${this._data}
.hass=${this.hass}
.error=${this._error}
.computeLabel=${this._computeLabel}
@value-changed=${this._valueChanged}
></ha-form>
`}
: html`
<ha-form
.schema=${this._schema(this._params)}
.data=${this._data}
.hass=${this.hass}
.error=${this._error}
.computeLabel=${this._computeLabel}
@value-changed=${this._valueChanged}
></ha-form>
`}
</div>
${this._params.urlPath
? html`

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,
@@ -340,7 +327,7 @@ export class LovelacePanel extends LitElement {
}
public get urlPath() {
return this.panel!.url_path === "lovelace" ? null : this.panel!.url_path;
return this.panel!.url_path;
}
private _forceFetchConfig() {
@@ -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.