1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-02-15 07:25:54 +00:00

Fix default lovelace yaml loading (#29240)

This commit is contained in:
Paul Bottein
2026-01-29 23:26:39 +01:00
committed by GitHub
parent c223f932f3
commit 157e89e5e7
4 changed files with 32 additions and 14 deletions

View File

@@ -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<LovelaceInfo> =>
hass.callWS({
type: "lovelace/info",
});

View File

@@ -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"

View File

@@ -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 {

View File

@@ -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",