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
10 changed files with 68 additions and 159 deletions

View File

@@ -1,29 +0,0 @@
export interface ProcessedConfigurationUrl {
url: string;
isLocal: boolean;
}
/**
* Get a processed configuration URL, converting homeassistant:// URLs to local paths
* and determining if it should be opened locally or in a new tab.
*
* @param configurationUrl - The configuration URL to process
* @returns Processed URL and whether it's a local link, or null if URL is empty
*/
export const getConfigurationUrl = (
configurationUrl: string | null | undefined
): ProcessedConfigurationUrl | null => {
if (!configurationUrl) {
return null;
}
const isHomeAssistant = configurationUrl.startsWith("homeassistant://");
const url = isHomeAssistant
? configurationUrl.replace("homeassistant://", "/")
: configurationUrl;
return {
url,
isLocal: isHomeAssistant,
};
};

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

@@ -27,7 +27,6 @@ export interface ConfigEntry {
reason: string | null;
error_reason_translation_key: string | null;
error_reason_translation_placeholders: Record<string, string> | null;
configuration_url?: string | null;
}
export interface SubEntry {

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

@@ -26,7 +26,6 @@ import { computeStateName } from "../../../common/entity/compute_state_name";
import { stringCompare } from "../../../common/string/compare";
import { slugify } from "../../../common/string/slugify";
import { groupBy } from "../../../common/util/group-by";
import { getConfigurationUrl } from "../../../common/util/configuration-url";
import "../../../components/entity/ha-battery-icon";
import "../../../components/ha-alert";
import "../../../components/ha-button";
@@ -1091,12 +1090,17 @@ export class HaConfigDevicePage extends LitElement {
const deviceActions: DeviceAction[] = [];
const processedUrl = getConfigurationUrl(device.configuration_url);
const configurationUrlIsHomeAssistant =
device.configuration_url?.startsWith("homeassistant://") || false;
if (processedUrl) {
const configurationUrl = configurationUrlIsHomeAssistant
? device.configuration_url!.replace("homeassistant://", "/")
: device.configuration_url;
if (configurationUrl) {
deviceActions.push({
href: processedUrl.url,
target: processedUrl.isLocal ? undefined : "_blank",
href: configurationUrl,
target: configurationUrlIsHomeAssistant ? undefined : "_blank",
icon: mdiCog,
label: this.hass.localize(
"ui.panel.config.devices.open_configuration_url"

View File

@@ -8,7 +8,6 @@ import {
mdiDotsVertical,
mdiDownload,
mdiHandExtendedOutline,
mdiOpenInNew,
mdiPlayCircleOutline,
mdiPlus,
mdiProgressHelper,
@@ -74,7 +73,6 @@ import "./ha-config-entry-device-row";
import { renderConfigEntryError } from "./ha-config-integration-page";
import "./ha-config-sub-entry-row";
import { copyToClipboard } from "../../../common/util/copy-clipboard";
import { getConfigurationUrl } from "../../../common/util/configuration-url";
import { showToast } from "../../../util/toast";
@customElement("ha-config-entry-row")
@@ -215,53 +213,34 @@ class HaConfigEntryRow extends LitElement {
? html`<ha-button slot="end" @click=${this._handleEnable}>
${this.hass.localize("ui.common.enable")}
</ha-button>`
: (() => {
const processedUrl = getConfigurationUrl(item.configuration_url);
return html`
${processedUrl
? html`<a
slot="end"
href=${processedUrl.url}
target=${processedUrl.isLocal ? undefined : "_blank"}
rel=${processedUrl.isLocal ? undefined : "noreferrer"}
>
<ha-icon-button
.path=${mdiOpenInNew}
.label=${processedUrl.url}
></ha-icon-button>
</a>`
: nothing}
${configPanel &&
(item.domain !== "matter" ||
isDevVersion(this.hass.config.version)) &&
!stateText
? html`<a
slot="end"
href=${`/${configPanel}?config_entry=${item.entry_id}`}
><ha-icon-button
.path=${mdiCogOutline}
.label=${this.hass.localize(
"ui.panel.config.integrations.config_entry.configure"
)}
>
</ha-icon-button
></a>`
: item.supports_options
? html`
<ha-icon-button
slot="end"
@click=${this._showOptions}
.path=${mdiCogOutline}
.label=${this.hass.localize(
"ui.panel.config.integrations.config_entry.configure"
)}
>
</ha-icon-button>
`
: nothing}
`;
})()}
: configPanel &&
(item.domain !== "matter" ||
isDevVersion(this.hass.config.version)) &&
!stateText
? html`<a
slot="end"
href=${`/${configPanel}?config_entry=${item.entry_id}`}
><ha-icon-button
.path=${mdiCogOutline}
.label=${this.hass.localize(
"ui.panel.config.integrations.config_entry.configure"
)}
>
</ha-icon-button
></a>`
: item.supports_options
? html`
<ha-icon-button
slot="end"
@click=${this._showOptions}
.path=${mdiCogOutline}
.label=${this.hass.localize(
"ui.panel.config.integrations.config_entry.configure"
)}
>
</ha-icon-button>
`
: nothing}
<ha-md-button-menu positioning="popover" slot="end">
<ha-icon-button
slot="trigger"

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.