Compare commits

..
Author SHA1 Message Date
renovate[bot] cf98d39240 Update dependency mermaid to v12.4.1 (#56496)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-12-04 20:29:37 +02:00
renovate[bot] 218492b655 Update dependency globals to v17.15.0 (#56494)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-12-04 17:30:12 +00:00
ChrisandClaude Opus 5.5 f5b44ed025 Preload the config of the dashboard opened from the URL (#56217)
* Preload the config of the dashboard opened from the URL

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Skip paths that cannot be a dashboard

media-browser is a built-in panel with a hyphen in its path, and
developer-tools is still read from the URL before the redirect to
/config/tools runs. Neither can be a dashboard, so neither preloads a
config that is bound to fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Test that the dashboard uses its own preloaded config

The existing tests only cover which URL paths start a preload, so they
would still pass if the panel discarded every preload, used another
dashboard's config, or never refetched after a failed preload.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
2026-12-04 16:34:20 +01:00
18 changed files with 219 additions and 356 deletions

No files matched your search

+2 -2
View File
@@ -113,7 +113,7 @@
"marked-footnote": "1.4.0",
"marked-gfm-heading-id": "4.1.4",
"memoize-one": "7.0.0",
"mermaid": "12.4.0",
"mermaid": "12.4.1",
"nanoid": "6.0.2",
"node-vibrant": "4.0.4",
"object-hash": "3.0.0",
@@ -191,7 +191,7 @@
"fs-extra": "11.4.1",
"generate-license-file": "4.2.5",
"glob": "15.0.0",
"globals": "17.14.0",
"globals": "17.15.0",
"gulp": "5.0.1",
"gulp-json-transform": "0.5.0",
"gulp-rename": "2.1.0",
+10 -10
View File
@@ -419,8 +419,8 @@ importers:
specifier: 7.0.0
version: 7.0.0
mermaid:
specifier: 12.4.0
version: 12.4.0
specifier: 12.4.1
version: 12.4.1
nanoid:
specifier: 6.0.2
version: 6.0.2
@@ -648,8 +648,8 @@ importers:
specifier: 15.0.0
version: 15.0.0
globals:
specifier: 17.14.0
version: 17.14.0
specifier: 17.15.0
version: 17.15.0
gulp:
specifier: 5.0.1
version: 5.0.1
@@ -5747,8 +5747,8 @@ packages:
resolution: {integrity: sha512-5lsx1NUDHtSjfg0eHlmYvZKv8/nVqX4ckFbM+FrGcQ+04KWcWFo9P5MxPZYSzUvyzmdTbI7Eix8Q4IbELDqzKg==}
engines: {node: '>=0.10.0'}
[email protected]4.0:
resolution: {integrity: sha512-UtdkTVyAJePQv0J2M9Xe4L0ruNSDV314XiIJsADI2Zf40bcdAonE/D/OhAU8AT99oij9mhLByb+NvA3QWZYgCg==}
[email protected]5.0:
resolution: {integrity: sha512-OyBOdPnzu9B2lFpums9/4wcyNHx4haAxY2X5PgO9LqCvXJgKYMMr/1y4TU7om/vTy4eYqRsVes1ZTJEJYKap8Q==}
engines: {node: '>=18'}
[email protected]:
@@ -6607,8 +6607,8 @@ packages:
resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
engines: {node: '>= 8'}
[email protected].0:
resolution: {integrity: sha512-j2gvsGUFeS/53WdYLl9H5G2YtMZX9G/PlCvV3E5Pf4j5XSnK19DwazU6wki7OTcKeYKed7+qujRDLhy8NV2zBg==}
[email protected].1:
resolution: {integrity: sha512-8uCLCSeow+N6CrNzAB54lbNFipC1DOPXZeOTeSlfvJaNUohg0A9eebmJNxs4Ik/OyEDqmF2thvyCzkwkmNnTtg==}
engines: {node: '>=22.12.0'}
[email protected]:
@@ -14181,7 +14181,7 @@ snapshots:
is-windows: 1.0.2
which: 1.3.1
[email protected]4.0: {}
[email protected]5.0: {}
[email protected]:
dependencies:
@@ -15065,7 +15065,7 @@ snapshots:
[email protected]: {}
[email protected].0:
[email protected].1:
dependencies:
'@braintree/sanitize-url': 7.1.2
'@iconify/utils': 3.1.7
+3 -5
View File
@@ -1,7 +1,6 @@
import {
closeAllDialogs,
DIALOG_WAIT_TIMEOUT,
isDialogHistoryEntry,
updateClosedDialogSearch,
} from "../dialogs/make-dialog-manager";
import { fireEvent } from "./dom/fire_event";
@@ -70,10 +69,9 @@ export const setRefreshUrl = (path: string) => {
* Returns true if navigation can proceed, false if a dialog refused to close.
*/
const ensureDialogsClosed = async (timestamp: number): Promise<boolean> => {
if (
!isDialogHistoryEntry() ||
Date.now() - timestamp >= DIALOG_WAIT_TIMEOUT
) {
const { history } = mainWindow;
if (!history.state?.dialog || Date.now() - timestamp >= DIALOG_WAIT_TIMEOUT) {
return true;
}
+16
View File
@@ -4,6 +4,22 @@ import type { RecorderInfo } from "./recorder";
export interface WindowWithPreloads extends Window {
llConfProm?: Promise<LovelaceRawConfig>;
llConfUrlPath?: string;
llResProm?: Promise<LovelaceResource[]>;
recorderInfoProm?: Promise<RecorderInfo>;
}
const HYPHENATED_NON_DASHBOARD_PATHS = ["developer-tools", "media-browser"];
export const getPreloadDashboardUrlPath = (
pathname: string
): string | undefined => {
const urlPath = pathname.split("/")[1];
if (urlPath === "lovelace") {
return urlPath;
}
return urlPath?.includes("-") &&
!HYPHENATED_NON_DASHBOARD_PATHS.includes(urlPath)
? urlPath
: undefined;
};
+10 -26
View File
@@ -40,10 +40,6 @@ export const DialogHistoryMixin = <
private _hasManagerHistoryEntry = false;
// Depth of the current level, also while a dialog opened over this one
// has replaced its history entry
private _historyDepth = 0;
private _historyPending = false;
private _closedWhileHistoryPending = false;
@@ -66,14 +62,12 @@ export const DialogHistoryMixin = <
}
// Navigating back in history goes up a level instead of closing
if (!this._historyClosing && historyState) {
const level = this._ownHistoryData(historyState);
if (this.restoreHistoryLevel(level)) {
if (level) {
this._historyDepth = level.depth;
}
return false;
}
if (
!this._historyClosing &&
historyState &&
this.restoreHistoryLevel(this._ownHistoryData(historyState))
) {
return false;
}
if (!this._historyClosing) {
@@ -99,21 +93,17 @@ export const DialogHistoryMixin = <
}
protected pushHistoryLevel(level: L) {
// Code that runs on after closing may still pick a level
if (this._historyClosing || !this.isConnected) {
return;
}
if (!this._historyDepth) {
const current = this._ownHistoryData(mainWindow.history.state);
if (!current) {
this._hasManagerHistoryEntry =
mainWindow.history.state?.dialog === this.localName;
}
this._historyDepth++;
mainWindow.history.pushState(
{
dialogData: {
...level,
dialogId: this._historyId,
depth: this._historyDepth,
depth: (current?.depth ?? 0) + 1,
},
},
""
@@ -134,13 +124,7 @@ export const DialogHistoryMixin = <
// Goes back to the opener entry, where the dialog manager closes this
// dialog as the top one, so a dialog below it stays open.
private _unwindHistory(): boolean {
const { state } = mainWindow.history;
const depth =
this._ownHistoryData(state)?.depth ??
// A dialog opened over this one replaced the current level's entry
(state?.dialog && state.dialog !== this.localName
? this._historyDepth
: undefined);
const depth = this._ownHistoryData(mainWindow.history.state)?.depth;
if (!depth) {
return false;
}
+9 -69
View File
@@ -53,9 +53,6 @@ export interface DialogState {
dialogParams: unknown;
dialogImport?: () => Promise<unknown>;
addHistory?: boolean;
// The history entry of a level of the dialog below (see
// DialogHistoryMixin), which the entry of this dialog replaced
replacedLevel?: unknown;
}
interface LoadedDialogInfo {
@@ -93,41 +90,6 @@ const _removeOpenDialogTag = (dialogTag: string) => {
}
};
// An entry a dialog pushed for one of its levels (see DialogHistoryMixin),
// while that dialog is still open
const isLevelOfOpenDialog = (historyState: any): boolean =>
Boolean(historyState?.dialogData && OPEN_DIALOG_STACK.length);
/**
* Whether Back went from a dialog to the entry of a dialog below it, which
* only has its own entry under its first level (see DialogHistoryMixin).
*/
export const isEntryOfDialogBelow = (historyState: any): boolean =>
OPEN_DIALOG_STACK.slice(0, -1).some(
(dialog) => dialog.dialogTag === historyState?.dialog
);
// Whether Back went from a dialog over a level to the dialog below, not to
// a level of its own
const wentToDialogBelow = (dialog: DialogState, historyState: any) => {
const level = dialog.replacedLevel as
{ dialogData: { dialogId: string } } | undefined;
return Boolean(
level &&
(historyState?.dialog ||
historyState?.dialogData?.dialogId === level.dialogData.dialogId)
);
};
/**
* Whether the current history entry belongs to an open dialog, so leaving
* the page must wait until the dialogs closed and went back past it.
*/
export const isDialogHistoryEntry = (): boolean => {
const { state } = mainWindow.history;
return Boolean(state?.dialog) || isLevelOfOpenDialog(state);
};
/**
* Returns the tag name of the topmost open dialog, or `undefined` when no
* dialog is open.
@@ -229,23 +191,18 @@ export const showDialog = async (
const dialogIndex = OPEN_DIALOG_STACK.findIndex(
(state) => state.dialogTag === dialogTag
);
const shownState =
dialogIndex !== -1
? OPEN_DIALOG_STACK.splice(dialogIndex, 1)[0]
: undefined;
const replacedLevel = isLevelOfOpenDialog(history.state)
? history.state
: shownState?.replacedLevel;
if (dialogIndex !== -1) {
OPEN_DIALOG_STACK.splice(dialogIndex, 1);
}
OPEN_DIALOG_STACK.push({
element,
dialogTag,
dialogParams,
dialogImport,
addHistory,
replacedLevel,
});
const newState = { dialog: dialogTag };
if (history.state?.dialog || replacedLevel) {
if (history.state?.dialog) {
// if a dialog is already open, replace the name
history.replaceState(newState, "");
} else {
@@ -324,17 +281,9 @@ export const closeLastDialog = async (historyState?: any) => {
if (!closed) {
// if the dialog was not closed, put it back on the stack
OPEN_DIALOG_STACK.push(lastDialog);
if (wentToDialogBelow(lastDialog, historyState)) {
mainWindow.history.pushState({ dialog: lastDialog.dialogTag }, "");
}
} else if (lastDialog.replacedLevel && historyState) {
// Back went past the level the dialog below is still on
mainWindow.history.pushState(lastDialog.replacedLevel, "");
} else if (
OPEN_DIALOG_STACK.length &&
(mainWindow.history.state?.opensDialog ||
// Back went past the level a dialog below covers
OPEN_DIALOG_STACK.some((dialog) => dialog.replacedLevel))
mainWindow.history.state?.opensDialog
) {
// if there are more dialogs open, push a new state so back() will close the next top dialog
mainWindow.history.pushState(
@@ -411,17 +360,14 @@ const _handleClosed = (ev: HASSDomEvent<DialogClosedParams>) => {
const dialogIndex = OPEN_DIALOG_STACK.findIndex(
(state) => state.dialogTag === ev.detail.dialog
);
const closedState =
dialogIndex !== -1
? OPEN_DIALOG_STACK.splice(dialogIndex, 1)[0]
: undefined;
if (dialogIndex !== -1) {
OPEN_DIALOG_STACK.splice(dialogIndex, 1);
}
if (mainWindow.history.state?.dialog === ev.detail.dialog) {
if (OPEN_DIALOG_STACK.length) {
// if there are more dialogs open, set the top one in history
mainWindow.history.replaceState(
closedState?.replacedLevel ?? {
dialog: OPEN_DIALOG_STACK[OPEN_DIALOG_STACK.length - 1].dialogTag,
},
{ dialog: OPEN_DIALOG_STACK[OPEN_DIALOG_STACK.length - 1].dialogTag },
""
);
} else if (dialogIndex !== -1) {
@@ -430,12 +376,6 @@ const _handleClosed = (ev: HASSDomEvent<DialogClosedParams>) => {
closedDialogUrl = { pathname, search };
mainWindow.history.back();
}
} else if (
closedState?.replacedLevel &&
dialogIndex < OPEN_DIALOG_STACK.length
) {
// The dialog above took over the entry that covers the level
OPEN_DIALOG_STACK[dialogIndex].replacedLevel ??= closedState.replacedLevel;
}
const loaded = ev.detail.dialog ? LOADED[ev.detail.dialog] : undefined;
+9 -4
View File
@@ -14,7 +14,10 @@ import { isExternal } from "../data/external";
import { fetchConfig } from "../data/lovelace/config/types";
import { fetchResources } from "../data/lovelace/resource";
import { MAIN_WINDOW_NAME } from "../data/main_window";
import type { WindowWithPreloads } from "../data/preloads";
import {
getPreloadDashboardUrlPath,
type WindowWithPreloads,
} from "../data/preloads";
import { getRecorderInfo } from "../data/recorder";
import { subscribeRepairsIssueRegistry } from "../data/repairs";
import { subscribeAreaRegistry } from "../data/ws-area_registry";
@@ -193,9 +196,11 @@ window.hassConnection.then(({ conn }) => {
preloadWindow.recorderInfoProm = getRecorderInfo(conn);
// "/" opens the default panel, which is not known yet, so only preload the
// config when the "lovelace" dashboard is opened directly.
if (location.pathname.startsWith("/lovelace/")) {
preloadWindow.llConfProm = fetchConfig(conn, "lovelace", false);
// config when a dashboard is opened directly.
const dashboardUrlPath = getPreloadDashboardUrlPath(location.pathname);
if (dashboardUrlPath) {
preloadWindow.llConfUrlPath = dashboardUrlPath;
preloadWindow.llConfProm = fetchConfig(conn, dashboardUrlPath, false);
preloadWindow.llConfProm.catch(() => {
// Ignore it, it is handled by Lovelace panel.
});
@@ -87,7 +87,7 @@ import {
getIntegrationDescriptions,
} from "../../../data/integrations";
import { showConfigFlowDialog } from "../../../dialogs/config-flow/show-dialog-config-flow";
import { DialogHistoryMixin } from "../../../dialogs/dialog-history-mixin";
import { DialogMixin } from "../../../dialogs/dialog-mixin";
import {
showAlertDialog,
showConfirmationDialog,
@@ -130,19 +130,10 @@ import type { AddIntegrationDialogParams } from "./show-add-integration-dialog";
import { showYamlIntegrationDialog } from "./show-add-integration-dialog";
import { showSingleConfigEntryWarning } from "./show-single-config-entry-warning";
// A view the dialog went into, so Back returns from it
interface AddIntegrationHistoryLevel {
drilled?: boolean;
subcategory?: string;
pickedBrand?: string;
discoveredDomain?: string;
}
@customElement("dialog-add-integration")
class AddIntegrationDialog extends DialogHistoryMixin<
AddIntegrationDialogParams,
AddIntegrationHistoryLevel
>(LitElement) {
class AddIntegrationDialog extends DialogMixin<AddIntegrationDialogParams>(
LitElement
) {
@state()
@consume({ context: internationalizationContext, subscribe: true })
private _i18n!: HomeAssistantInternationalization;
@@ -208,6 +199,8 @@ class AddIntegrationDialog extends DialogHistoryMixin<
@state() private _brand?: string;
@state() private _prevPickedBrand?: string;
@state() private _flowsInProgress?: DataEntryFlowProgress[];
@state() private _showDiscovered = false;
@@ -316,52 +309,7 @@ class AddIntegrationDialog extends DialogHistoryMixin<
);
this._narrowQuery.addEventListener("change", this._narrowChanged);
this._narrow = this._narrowQuery.matches;
this._pushHistoryLevel();
if (this._narrow && params?.category) {
// Back returns to the categories, like after picking it there
this._drilled = true;
this._pushDrilledLevels(false);
}
}
private _pushHistoryLevel(level: AddIntegrationHistoryLevel = {}) {
this.pushHistoryLevel({
drilled: this._drilled,
subcategory: this._subcategory,
pickedBrand: this._pickedBrand,
discoveredDomain: this._discoveredDomain,
...level,
});
}
// Back from a subcategory goes to its category first, also when it was
// picked from outside the category, like a search result
private _pushDrilledLevels(wasDrilled: boolean) {
if (this._subcategory && !wasDrilled) {
this._pushHistoryLevel({ subcategory: undefined });
}
this._pushHistoryLevel();
}
protected restoreHistoryLevel(level: AddIntegrationHistoryLevel | undefined) {
if (!level) {
return false;
}
if (this._narrow && this._drilled && !level.drilled) {
this._focusAfterDrill = "out";
}
const discoveredDomain = this._discoveredDomain;
this._drilled = !!level.drilled;
// Wide, the subcategory is picked in the browse pane, not a level
if (this._narrow) {
this._subcategory = level.subcategory;
}
this._pickedBrand = level.pickedBrand;
this._discoveredDomain = level.discoveredDomain;
if (discoveredDomain && !level.discoveredDomain) {
this._focusFlowGroupAfterBack(discoveredDomain);
}
return true;
this._drilled = this._narrow && !!params?.category;
}
private _pickProtocol(domain: string, brand?: string) {
@@ -1068,7 +1016,7 @@ class AddIntegrationDialog extends DialogHistoryMixin<
? html`
<ha-icon-button-prev
slot="headerNavigationIcon"
@click=${this.historyBack}
@click=${this._prevClicked}
></ha-icon-button-prev>
`
: nothing
@@ -1085,7 +1033,7 @@ class AddIntegrationDialog extends DialogHistoryMixin<
this._narrow && this._drilled
? html`<ha-icon-button-prev
slot="headerNavigationIcon"
@click=${this.historyBack}
@click=${this._drillOut}
></ha-icon-button-prev>`
: nothing
}
@@ -1186,12 +1134,13 @@ class AddIntegrationDialog extends DialogHistoryMixin<
.domain=${domain}
.integration=${integration}
.flowsInProgress=${flowsInProgress}
.navigateToResult=${this._navigateToResult}
.showManageLink=${this._showDiscovered || this._showDiscoveredView}
.boxed=${!integration}
.groupFlows=${groupFlows}
.brands=${this._integrations}
.dialogParent=${this._dialogParent}
@close-dialog=${this._closeDialog}
@config-flow-picked=${this._handleConfigFlowPicked}
@protocol-picked=${this._handleProtocolPicked}
@supported-by=${this._handleSupportedByEvent}
@select-brand=${this._handleSelectBrandEvent}
@@ -1203,24 +1152,17 @@ class AddIntegrationDialog extends DialogHistoryMixin<
this.closeDialog();
}
private async _handleProtocolPicked(
private _handleProtocolPicked(
ev: HASSDomEvent<HASSDomEvents["protocol-picked"]>
) {
await this.closeDialog();
this.closeDialog();
this._pickProtocol(ev.detail.domain, ev.detail.brand);
}
private _handleConfigFlowPicked(
ev: HASSDomEvent<HASSDomEvents["config-flow-picked"]>
) {
this._showConfigFlow(ev.detail.domain, ev.detail.flowId);
}
private async _handleDiscoveredGroupPicked(
ev: HASSDomEvent<HASSDomEvents["discovered-group-picked"]>
) {
this._discoveredDomain = ev.detail.domain;
this._pushHistoryLevel();
// The picked row is gone, and the back button renders after this element
await nextRender();
if (this._discoveredDomain) {
@@ -1229,8 +1171,8 @@ class AddIntegrationDialog extends DialogHistoryMixin<
}
private _handleSelectBrandEvent(ev: CustomEvent) {
this._prevPickedBrand = this._pickedBrand;
this._pickedBrand = ev.detail.brand;
this._pushHistoryLevel();
}
private _handleSupportedByEvent(ev: CustomEvent) {
@@ -1254,8 +1196,8 @@ class AddIntegrationDialog extends DialogHistoryMixin<
domainToName(this._i18n.localize, integration.supported_by),
}
),
confirm: async () => {
await this.closeDialog();
confirm: () => {
this.closeDialog();
if (PROTOCOL_INTEGRATIONS.includes(integration.supported_by)) {
this._pickProtocol(integration.supported_by);
return;
@@ -1614,10 +1556,17 @@ class AddIntegrationDialog extends DialogHistoryMixin<
if (!this._narrow) {
return;
}
const wasDrilled = this._drilled;
this._drilled = true;
this._focusAfterDrill = "in";
this._pushDrilledLevels(wasDrilled);
}
private _drillOut() {
if (this._subcategory) {
this._subcategory = undefined;
return;
}
this._drilled = false;
this._focusAfterDrill = "out";
}
private _withEndSpace = memoizeOne(
@@ -1861,12 +1810,12 @@ class AddIntegrationDialog extends DialogHistoryMixin<
this._browse({ discovered: true });
}
private async _protocolPicked(
private _protocolPicked(
ev: HASSDomCurrentTargetEvent<HaListItemButton & { protocol: string }>
) {
const domain = ev.currentTarget.protocol;
await this.closeDialog();
this._pickProtocol(domain);
this.closeDialog();
}
private _treeSelectionChanged(ev: WaSelectionChangeEvent) {
@@ -2085,20 +2034,19 @@ class AddIntegrationDialog extends DialogHistoryMixin<
}
if (integration.is_add) {
await this.closeDialog();
this._pickProtocol(integration.domain);
this.closeDialog();
return;
}
if (integration.is_helper) {
await this.closeDialog();
this.closeDialog();
navigate(`/config/helpers/add?domain=${integration.domain}`);
return;
}
if (integration.integrations) {
this._pickedBrand = integration.domain;
this._pushHistoryLevel();
return;
}
@@ -2110,13 +2058,11 @@ class AddIntegrationDialog extends DialogHistoryMixin<
this._hasProtocol(integration.domain)
) {
this._pickedBrand = integration.domain;
this._pushHistoryLevel();
return;
}
if (integration.iot_standards) {
this._pickedBrand = integration.domain;
this._pushHistoryLevel();
return;
}
@@ -2125,10 +2071,9 @@ class AddIntegrationDialog extends DialogHistoryMixin<
domain: integration.domain,
});
if (configEntries.length > 0) {
await this.closeDialog();
showSingleConfigEntryWarning(this._dialogParent, {
domain: integration.domain,
});
this.closeDialog();
showSingleConfigEntryWarning(this, { domain: integration.domain });
return;
}
}
@@ -2142,7 +2087,7 @@ class AddIntegrationDialog extends DialogHistoryMixin<
integration.domain === "cloud" &&
isComponentLoaded(this._hassConfig, "cloud")
) {
await this.closeDialog();
this.closeDialog();
navigate("/config/cloud");
return;
}
@@ -2151,7 +2096,7 @@ class AddIntegrationDialog extends DialogHistoryMixin<
["google_assistant", "alexa"].includes(integration.domain) &&
isComponentLoaded(this._hassConfig, "cloud")
) {
await this.closeDialog();
this.closeDialog();
navigate("/config/voice-assistants/assistants");
return;
}
@@ -2171,20 +2116,15 @@ class AddIntegrationDialog extends DialogHistoryMixin<
if (flowsInProgress.length) {
this._pickedBrand = domain;
this._pushHistoryLevel();
return;
}
await this._showConfigFlow(domain);
}
private async _showConfigFlow(domain: string, flowId?: string) {
const manifest = await fetchIntegrationManifest(this._api, domain);
// Its history entry must not go on top of this dialog's levels
await this.closeDialog();
this.closeDialog();
showConfigFlowDialog(this._dialogParent, {
startFlowHandler: flowId ? undefined : domain,
continueFlowId: flowId,
startFlowHandler: domain,
manifest,
navigateToResult: this._navigateToResult,
});
@@ -2234,6 +2174,21 @@ class AddIntegrationDialog extends DialogHistoryMixin<
}
}
private _prevClicked() {
if (this._pickedBrand) {
this._pickedBrand = this._prevPickedBrand;
this._prevPickedBrand = undefined;
return;
}
if (this._discoveredDomain) {
const domain = this._discoveredDomain;
this._discoveredDomain = undefined;
this._focusFlowGroupAfterBack(domain);
return;
}
this._showDiscovered = false;
}
private async _focusFlowGroupAfterBack(domain: string) {
await nextRender();
if (this._open && !this._discoveredDomain) {
@@ -32,6 +32,7 @@ import {
} from "../../../data/integration";
import type { Brand, Brands, Integration } from "../../../data/integrations";
import { findIntegration } from "../../../data/integrations";
import { showConfigFlowDialog } from "../../../dialogs/config-flow/show-dialog-config-flow";
import { haStyle } from "../../../resources/styles";
import type {
HomeAssistantApi,
@@ -86,6 +87,9 @@ export class HaDomainIntegrations extends LitElement {
@property({ attribute: false })
public flowsInProgress?: DataEntryFlowProgress[];
@property({ attribute: false })
public navigateToResult = false;
@property({ attribute: false })
public showManageLink = false;
@@ -97,6 +101,9 @@ export class HaDomainIntegrations extends LitElement {
/** Names integrations that have no translated title, like most that aren't set up. */
@property({ attribute: false }) public brands?: Brands;
/** Opens the config flow, which keeps it to open dialogs after the add dialog has closed. */
@property({ attribute: false }) public dialogParent?: HTMLElement;
@queryAll("ha-list-item-button.flow-group")
private _flowGroups!: NodeListOf<HaListItemButton & { domain: string }>;
@@ -454,15 +461,22 @@ export class HaDomainIntegrations extends LitElement {
return;
}
fireEvent(this, "config-flow-picked", { domain });
showConfigFlowDialog(this.dialogParent ?? this, {
startFlowHandler: domain,
navigateToResult: this.navigateToResult,
manifest: await fetchIntegrationManifest(this._api, domain),
});
fireEvent(this, "close-dialog");
}
private _flowInProgressPicked(ev: Event) {
private async _flowInProgressPicked(ev: Event) {
const flow: DataEntryFlowProgress = (ev.currentTarget as any).flow;
fireEvent(this, "config-flow-picked", {
domain: flow.handler,
flowId: flow.flow_id,
showConfigFlowDialog(this.dialogParent ?? this, {
continueFlowId: flow.flow_id,
navigateToResult: this.navigateToResult,
manifest: await fetchIntegrationManifest(this._api, flow.handler),
});
fireEvent(this, "close-dialog");
}
private _manageDiscovered() {
@@ -595,8 +609,6 @@ declare global {
}
interface HASSDomEvents {
// The add dialog starts it, so it can close first
"config-flow-picked": { domain: string; flowId?: string };
"discovered-group-picked": { domain: string };
"protocol-picked": { domain: string; brand?: string };
}
@@ -1,3 +1,4 @@
import type { LitElement } from "lit";
import { fireEvent } from "../../../common/dom/fire_event";
export interface SingleConfigEntryWarningDialogParams {
@@ -5,7 +6,7 @@ export interface SingleConfigEntryWarningDialogParams {
}
export const showSingleConfigEntryWarning = (
element: HTMLElement,
element: LitElement,
params: SingleConfigEntryWarningDialogParams
) =>
fireEvent(element, "show-dialog", {
+5 -6
View File
@@ -315,7 +315,9 @@ export class LovelacePanel extends LitElement {
// On first load, we speed up loading page by having LL promise ready
if (preloadWindow.llConfProm) {
confProm = preloadWindow.llConfProm;
if (preloadWindow.llConfUrlPath === this.urlPath) {
confProm = preloadWindow.llConfProm;
}
preloadWindow.llConfProm = undefined;
}
if (!resourcesLoaded) {
@@ -333,12 +335,9 @@ export class LovelacePanel extends LitElement {
const fetchDashboardConfig = () =>
fetchConfig(this.hass!.connection, this.urlPath, forceDiskRefresh);
// The preload is the config of the "lovelace" dashboard. Fetch it again if
// The preload is the config of the dashboard in the URL. Fetch it again if
// it failed, for example because the connection dropped before it came back.
confProm =
confProm && this.urlPath === "lovelace"
? confProm.catch(fetchDashboardConfig)
: fetchDashboardConfig();
confProm = confProm?.catch(fetchDashboardConfig) ?? fetchDashboardConfig();
try {
rawConf = await confProm;
-3
View File
@@ -5,7 +5,6 @@ import { mainWindow } from "../common/dom/get_main_window";
import { updateHistoryState } from "../common/navigate";
import {
closeLastDialog,
isEntryOfDialogBelow,
restoreClosedDialogSearch,
} from "../dialogs/make-dialog-manager";
import type { ProvideHassElement } from "../mixins/provide-hass-lit-mixin";
@@ -79,8 +78,6 @@ export const urlSyncMixin = <
// if we have dialog data we are closing a dialog with appended state
// so dialog has the change to navigate back to the previous state
closeLastDialog(ev.state);
} else if (isEntryOfDialogBelow(ev.state)) {
closeLastDialog(ev.state);
} else if ("dialog" in ev.state) {
// coming to a dialog
// the dialog stack must be empty in this case so this state should be cleaned up
-1
View File
@@ -22,7 +22,6 @@ vi.mock("../../src/dialogs/make-dialog-manager", () => ({
window.history.replaceState(null, "");
return true;
}),
isDialogHistoryEntry: () => Boolean(window.history.state?.dialog),
}));
// Fabricates a raw entry like a document load, which navigate() never produces.
+34
View File
@@ -0,0 +1,34 @@
import { describe, expect, it } from "vitest";
import { getPreloadDashboardUrlPath } from "../../src/data/preloads";
describe("getPreloadDashboardUrlPath", () => {
it("returns the lovelace dashboard", () => {
expect(getPreloadDashboardUrlPath("/lovelace")).toBe("lovelace");
expect(getPreloadDashboardUrlPath("/lovelace/0")).toBe("lovelace");
});
it("returns a dashboard with a hyphen in its url path", () => {
expect(getPreloadDashboardUrlPath("/dashboard-test")).toBe(
"dashboard-test"
);
expect(getPreloadDashboardUrlPath("/dashboard-test/kitchen")).toBe(
"dashboard-test"
);
});
it("returns nothing when the default panel is opened", () => {
expect(getPreloadDashboardUrlPath("/")).toBeUndefined();
});
it("returns nothing for panels that cannot be a dashboard", () => {
expect(getPreloadDashboardUrlPath("/home")).toBeUndefined();
expect(getPreloadDashboardUrlPath("/config/dashboard")).toBeUndefined();
expect(getPreloadDashboardUrlPath("/lovelaces")).toBeUndefined();
expect(
getPreloadDashboardUrlPath("/media-browser/browser")
).toBeUndefined();
expect(
getPreloadDashboardUrlPath("/developer-tools/state")
).toBeUndefined();
});
});
@@ -84,8 +84,6 @@ describe("DialogHistoryMixin", () => {
expect(dialog.level).toBe(1);
expect(dialog.isConnected).toBe(true);
// A dialog opened over this one takes over the entry of the level
window.history.replaceState({ dialog: "test-other-dialog" }, "");
const closed = dialog.closeDialog();
expect(dialog.isConnected).toBe(true);
expect(await closed).toBe(true);
-121
View File
@@ -4,11 +4,8 @@ import { deepActiveElement } from "../../src/common/dom/deep-active-element";
import { fireEvent } from "../../src/common/dom/fire_event";
import { nextRender } from "../../src/common/util/render-status";
import {
closeLastDialog,
DIALOG_WAIT_TIMEOUT,
getTopOpenDialogTag,
isDialogHistoryEntry,
isEntryOfDialogBelow,
showDialog,
} from "../../src/dialogs/make-dialog-manager";
import type { ProvideHassElement } from "../../src/mixins/provide-hass-lit-mixin";
@@ -49,22 +46,11 @@ class TestFlowDialog extends TestNextDialog {}
class TestHistoryDialog extends TestNextDialog {}
class TestTopDialog extends TestNextDialog {}
// Like a confirmation, which only closes from its buttons
class TestRefusingDialog extends TestNextDialog {
public closeDialog() {
return false;
}
}
customElements.define("test-manager-dialog", TestDialog);
customElements.define("test-manager-nested-dialog", TestNestedDialog);
customElements.define("test-manager-next-dialog", TestNextDialog);
customElements.define("test-manager-flow-dialog", TestFlowDialog);
customElements.define("test-manager-history-dialog", TestHistoryDialog);
customElements.define("test-manager-top-dialog", TestTopDialog);
customElements.define("test-manager-refusing-dialog", TestRefusingDialog);
declare global {
interface HTMLElementTagNameMap {
@@ -73,8 +59,6 @@ declare global {
"test-manager-next-dialog": TestNextDialog;
"test-manager-flow-dialog": TestFlowDialog;
"test-manager-history-dialog": TestHistoryDialog;
"test-manager-top-dialog": TestTopDialog;
"test-manager-refusing-dialog": TestRefusingDialog;
}
}
@@ -245,108 +229,3 @@ describe("dialog manager history wait", () => {
}
});
});
// A dialog opened over a level of another dialog (see DialogHistoryMixin)
// must keep the number of history entries and give the level back, or Back
// and closing the lower dialog land on the wrong entry.
describe("dialog manager over a dialog level", () => {
it("works", async () => {
const element = host();
const showWithHistory = async (dialogTag: string) => {
await showDialog(element, dialogTag, {}, () => Promise.resolve());
return element.shadowRoot!.querySelector(dialogTag) as TestNextDialog;
};
const popstate = () =>
new Promise((resolve) => {
window.addEventListener("popstate", resolve, { once: true });
});
const level = (depth: number) => ({
dialogData: { dialogId: "lower", depth },
});
try {
window.history.replaceState({ opener: true }, "");
const lower = await showWithHistory("test-manager-next-dialog");
window.history.pushState(level(1), "");
window.history.pushState(level(2), "");
const { length } = window.history;
expect(isDialogHistoryEntry()).toBe(true);
let upper = await showWithHistory("test-manager-flow-dialog");
expect(window.history.state).toEqual({
dialog: "test-manager-flow-dialog",
});
expect(window.history.length).toBe(length);
upper.close();
expect(window.history.state).toEqual(level(2));
upper = await showWithHistory("test-manager-flow-dialog");
window.history.back();
await popstate();
// Like the url-sync mixin
await closeLastDialog(window.history.state);
expect(window.history.state).toEqual(level(2));
upper.close();
// Three dialogs over the level, Back closes one at a time
upper = await showWithHistory("test-manager-flow-dialog");
let top = await showWithHistory("test-manager-top-dialog");
const third = await showWithHistory("test-manager-history-dialog");
window.history.back();
await popstate();
await closeLastDialog(window.history.state);
third.close();
expect(window.history.state).toEqual({
dialog: "test-manager-top-dialog",
});
window.history.back();
await popstate();
await closeLastDialog(window.history.state);
top.close();
expect(window.history.state).toEqual({
dialog: "test-manager-flow-dialog",
});
window.history.back();
await popstate();
await closeLastDialog(window.history.state);
upper.close();
expect(window.history.state).toEqual(level(2));
// Shown again, then the next dialog takes over the entry
upper = await showWithHistory("test-manager-flow-dialog");
upper = await showWithHistory("test-manager-flow-dialog");
top = await showWithHistory("test-manager-top-dialog");
upper.close();
top.close();
expect(window.history.state).toEqual(level(2));
// Refusing Back keeps the dialog's entry
const refusing = await showWithHistory("test-manager-refusing-dialog");
window.history.back();
await popstate();
expect(await closeLastDialog(window.history.state)).toBe(false);
expect(window.history.state).toEqual({
dialog: "test-manager-refusing-dialog",
});
refusing.close();
expect(window.history.state).toEqual(level(2));
expect(window.history.length).toBe(length);
// Over the first level, Back lands on the lower dialog's own entry
window.history.back();
await popstate();
upper = await showWithHistory("test-manager-flow-dialog");
window.history.back();
await popstate();
expect(isEntryOfDialogBelow(window.history.state)).toBe(true);
await closeLastDialog(window.history.state);
expect(window.history.state).toEqual(level(1));
upper.close();
lower.close();
// Left behind, like after a page reload
expect(isDialogHistoryEntry()).toBe(false);
} finally {
window.history.replaceState(null, "");
}
});
});
@@ -7,7 +7,6 @@ import { PreventUnsavedMixin } from "../../src/mixins/prevent-unsaved-mixin";
// navigate() closes open dialogs before touching history.
vi.mock("../../src/dialogs/make-dialog-manager", () => ({
closeAllDialogs: vi.fn(async () => true),
isDialogHistoryEntry: () => Boolean(window.history.state?.dialog),
}));
interface TestState {
@@ -1,6 +1,8 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { subscribeLovelaceUpdates } from "../../../src/data/lovelace";
import type { LovelaceRawConfig } from "../../../src/data/lovelace/config/types";
import { fetchConfig } from "../../../src/data/lovelace/config/types";
import type { WindowWithPreloads } from "../../../src/data/preloads";
import "../../../src/panels/lovelace/ha-panel-lovelace";
type LovelacePanel = HTMLElement & {
@@ -63,9 +65,54 @@ const openPanel = async (urlPath: string) => {
return { panel, unsub, notifyUpdated: () => notifyUpdated() };
};
const preloadWindow = window as WindowWithPreloads;
const preloadConfig = (
urlPath: string,
confProm: Promise<LovelaceRawConfig>
) => {
confProm.catch(() => undefined);
preloadWindow.llConfUrlPath = urlPath;
preloadWindow.llConfProm = confProm;
};
afterEach(() => {
document.body.replaceChildren();
vi.clearAllMocks();
delete preloadWindow.llConfProm;
delete preloadWindow.llConfUrlPath;
});
describe("ha-panel-lovelace config preload", () => {
it("uses the preloaded config of its own dashboard", async () => {
preloadConfig("dashboard-test", Promise.resolve({ views: [] }));
await openPanel("dashboard-test");
expect(fetchConfig).not.toHaveBeenCalled();
expect(preloadWindow.llConfProm).toBeUndefined();
});
it("ignores the preloaded config of another dashboard", async () => {
preloadConfig("dashboard-other", Promise.resolve({ views: [] }));
await openPanel("dashboard-test");
expect(fetchConfig).toHaveBeenCalledTimes(1);
expect(fetchConfig).toHaveBeenCalledWith(
expect.anything(),
"dashboard-test",
false
);
expect(preloadWindow.llConfProm).toBeUndefined();
});
it("fetches the config again when its preload failed", async () => {
preloadConfig("dashboard-test", Promise.reject(new Error("closed")));
await openPanel("dashboard-test");
expect(fetchConfig).toHaveBeenCalledTimes(1);
expect(fetchConfig).toHaveBeenCalledWith(
expect.anything(),
"dashboard-test",
false
);
});
});
describe("ha-panel-lovelace config updates", () => {