From 157e89e5e76941a980f9721f911f298c56ecfc94 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Thu, 29 Jan 2026 23:26:39 +0100 Subject: [PATCH] Fix default lovelace yaml loading (#29240) --- src/data/lovelace/resource.ts | 9 ++++++++ .../resources/ha-config-lovelace-resources.ts | 23 ++++++++++++++----- src/panels/lovelace/ha-panel-lovelace.ts | 12 ++++------ src/translations/en.json | 2 +- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/data/lovelace/resource.ts b/src/data/lovelace/resource.ts index f0b877af89..05e1ab6446 100644 --- a/src/data/lovelace/resource.ts +++ b/src/data/lovelace/resource.ts @@ -1,6 +1,10 @@ import type { Connection } from "home-assistant-js-websocket"; import type { HomeAssistant } from "../../types"; +export interface LovelaceInfo { + resource_mode: "yaml" | "storage"; +} + export interface LovelaceResource { id: string; type: "css" | "js" | "module" | "html"; @@ -42,3 +46,8 @@ export const deleteResource = (hass: HomeAssistant, id: string) => type: "lovelace/resources/delete", resource_id: id, }); + +export const fetchLovelaceInfo = (hass: HomeAssistant): Promise => + hass.callWS({ + type: "lovelace/info", + }); diff --git a/src/panels/config/lovelace/resources/ha-config-lovelace-resources.ts b/src/panels/config/lovelace/resources/ha-config-lovelace-resources.ts index db2881a329..2b2924cea6 100644 --- a/src/panels/config/lovelace/resources/ha-config-lovelace-resources.ts +++ b/src/panels/config/lovelace/resources/ha-config-lovelace-resources.ts @@ -13,10 +13,14 @@ import type { import "../../../../components/ha-card"; import "../../../../components/ha-fab"; import "../../../../components/ha-svg-icon"; -import type { LovelaceResource } from "../../../../data/lovelace/resource"; +import type { + LovelaceInfo, + LovelaceResource, +} from "../../../../data/lovelace/resource"; import { createResource, deleteResource, + fetchLovelaceInfo, fetchResources, updateResource, } from "../../../../data/lovelace/resource"; @@ -46,6 +50,8 @@ export class HaConfigLovelaceResources extends LitElement { @state() private _resources: LovelaceResource[] = []; + @state() private _lovelaceInfo?: LovelaceInfo; + @state() @storage({ storage: "sessionStorage", @@ -197,15 +203,20 @@ export class HaConfigLovelaceResources extends LitElement { protected firstUpdated(changedProps: PropertyValues) { super.firstUpdated(changedProps); - this._getResources(); + this._fetchData(); } - private async _getResources() { - this._resources = await fetchResources(this.hass.connection); + private async _fetchData() { + const [resources, lovelaceInfo] = await Promise.all([ + fetchResources(this.hass.connection), + fetchLovelaceInfo(this.hass), + ]); + this._resources = resources; + this._lovelaceInfo = lovelaceInfo; } private _editResource(ev: CustomEvent) { - if ((this.hass.panels.lovelace?.config as any)?.mode !== "storage") { + if (this._lovelaceInfo?.resource_mode !== "storage") { showAlertDialog(this, { text: this.hass!.localize( "ui.panel.config.lovelace.resources.cant_edit_yaml" @@ -219,7 +230,7 @@ export class HaConfigLovelaceResources extends LitElement { } private _addResource() { - if ((this.hass.panels.lovelace?.config as any)?.mode !== "storage") { + if (this._lovelaceInfo?.resource_mode !== "storage") { showAlertDialog(this, { text: this.hass!.localize( "ui.panel.config.lovelace.resources.cant_edit_yaml" diff --git a/src/panels/lovelace/ha-panel-lovelace.ts b/src/panels/lovelace/ha-panel-lovelace.ts index d06c467400..467411b98b 100644 --- a/src/panels/lovelace/ha-panel-lovelace.ts +++ b/src/panels/lovelace/ha-panel-lovelace.ts @@ -368,13 +368,11 @@ export class LovelacePanel extends LitElement { this._ignoreNextUpdateEvent = true; } - // Keep lovelace yaml path for backward compatibility (until 2026.8) - const urlPath = - confMode === "yaml" && this.urlPath === "lovelace" - ? null - : this.urlPath; - - confProm = fetchConfig(this.hass!.connection, urlPath, forceDiskRefresh); + confProm = fetchConfig( + this.hass!.connection, + this.urlPath, + forceDiskRefresh + ); } try { diff --git a/src/translations/en.json b/src/translations/en.json index 35575568a1..4e4ab1ae47 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4249,7 +4249,7 @@ "confirm_delete_text": "{url} will be permanently deleted.", "refresh_header": "Do you want to refresh?", "refresh_body": "You have to refresh the page to complete the removal. Do you want to refresh now?", - "cant_edit_yaml": "You are using your dashboard in YAML mode, therefore you cannot manage your resources through the UI. Manage them in configuration.yaml.", + "cant_edit_yaml": "Your resources are in YAML mode, therefore you cannot manage them through the UI. Manage them in configuration.yaml.", "detail": { "new_resource": "Add new resource", "edit_resource": "Edit resource",