1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-20 10:48:44 +00:00

Wait for translations before showing home and domain dashboards (#28556)

This commit is contained in:
Paul Bottein
2025-12-16 08:11:15 +01:00
committed by GitHub
parent fd42614a23
commit e709703f79
4 changed files with 36 additions and 22 deletions

View File

@@ -37,8 +37,7 @@ class PanelClimate extends LitElement {
super.willUpdate(changedProps); super.willUpdate(changedProps);
// Initial setup // Initial setup
if (!this.hasUpdated) { if (!this.hasUpdated) {
this.hass.loadFragmentTranslation("lovelace"); this._setup();
this._setLovelace();
return; return;
} }
@@ -75,6 +74,11 @@ class PanelClimate extends LitElement {
} }
} }
private async _setup() {
await this.hass.loadFragmentTranslation("lovelace");
this._setLovelace();
}
private _debounceRegistriesChanged = debounce( private _debounceRegistriesChanged = debounce(
() => this._registriesChanged(), () => this._registriesChanged(),
200 200

View File

@@ -12,7 +12,7 @@ import type { LovelaceDashboardStrategyConfig } from "../../data/lovelace/config
import type { HomeAssistant, PanelInfo, Route } from "../../types"; import type { HomeAssistant, PanelInfo, Route } from "../../types";
import { showToast } from "../../util/toast"; import { showToast } from "../../util/toast";
import "../lovelace/hui-root"; import "../lovelace/hui-root";
import { generateLovelaceDashboardStrategy } from "../lovelace/strategies/get-strategy"; import { expandLovelaceConfigStrategies } from "../lovelace/strategies/get-strategy";
import type { Lovelace } from "../lovelace/types"; import type { Lovelace } from "../lovelace/types";
import { showEditHomeDialog } from "./dialogs/show-dialog-edit-home"; import { showEditHomeDialog } from "./dialogs/show-dialog-edit-home";
@@ -34,8 +34,7 @@ class PanelHome extends LitElement {
super.willUpdate(changedProps); super.willUpdate(changedProps);
// Initial setup // Initial setup
if (!this.hasUpdated) { if (!this.hasUpdated) {
this.hass.loadFragmentTranslation("lovelace"); this._setup();
this._loadConfig();
return; return;
} }
@@ -72,6 +71,21 @@ class PanelHome extends LitElement {
} }
} }
private async _setup() {
try {
const [_, data] = await Promise.all([
this.hass.loadFragmentTranslation("lovelace"),
fetchFrontendSystemData(this.hass.connection, "home"),
]);
this._config = data || {};
} catch (err) {
// eslint-disable-next-line no-console
console.error("Failed to load favorites:", err);
this._config = {};
}
this._setLovelace();
}
private _debounceRegistriesChanged = debounce( private _debounceRegistriesChanged = debounce(
() => this._registriesChanged(), () => this._registriesChanged(),
200 200
@@ -97,18 +111,6 @@ class PanelHome extends LitElement {
`; `;
} }
private async _loadConfig() {
try {
const data = await fetchFrontendSystemData(this.hass.connection, "home");
this._config = data || {};
} catch (err) {
// eslint-disable-next-line no-console
console.error("Failed to load favorites:", err);
this._config = {};
}
this._setLovelace();
}
private async _setLovelace() { private async _setLovelace() {
const strategyConfig: LovelaceDashboardStrategyConfig = { const strategyConfig: LovelaceDashboardStrategyConfig = {
strategy: { strategy: {
@@ -117,7 +119,7 @@ class PanelHome extends LitElement {
}, },
}; };
const config = await generateLovelaceDashboardStrategy( const config = await expandLovelaceConfigStrategies(
strategyConfig, strategyConfig,
this.hass this.hass
); );

View File

@@ -37,8 +37,7 @@ class PanelLight extends LitElement {
super.willUpdate(changedProps); super.willUpdate(changedProps);
// Initial setup // Initial setup
if (!this.hasUpdated) { if (!this.hasUpdated) {
this.hass.loadFragmentTranslation("lovelace"); this._setup();
this._setLovelace();
return; return;
} }
@@ -75,6 +74,11 @@ class PanelLight extends LitElement {
} }
} }
private async _setup() {
await this.hass.loadFragmentTranslation("lovelace");
this._setLovelace();
}
private _debounceRegistriesChanged = debounce( private _debounceRegistriesChanged = debounce(
() => this._registriesChanged(), () => this._registriesChanged(),
200 200

View File

@@ -37,8 +37,7 @@ class PanelSecurity extends LitElement {
super.willUpdate(changedProps); super.willUpdate(changedProps);
// Initial setup // Initial setup
if (!this.hasUpdated) { if (!this.hasUpdated) {
this.hass.loadFragmentTranslation("lovelace"); this._setup();
this._setLovelace();
return; return;
} }
@@ -75,6 +74,11 @@ class PanelSecurity extends LitElement {
} }
} }
private async _setup() {
await this.hass.loadFragmentTranslation("lovelace");
this._setLovelace();
}
private _debounceRegistriesChanged = debounce( private _debounceRegistriesChanged = debounce(
() => this._registriesChanged(), () => this._registriesChanged(),
200 200