Fix refresh strategy config on HA start-up (#24984)

This commit is contained in:
Paul Bottein 2025-04-10 10:04:43 +02:00 committed by Bram Kragten
parent ec9fbe7d77
commit 20f2a8d53e

View File

@ -183,21 +183,36 @@ export class LovelacePanel extends LitElement {
if (!changedProperties.has("hass")) { if (!changedProperties.has("hass")) {
return; return;
} }
const oldHass = changedProperties.get("hass") as HomeAssistant | undefined; const oldHass = changedProperties.get("hass") as HomeAssistant | undefined;
if ( if (
oldHass && oldHass &&
this.hass && this.hass &&
(oldHass.entities !== this.hass.entities || this.lovelace &&
isStrategyDashboard(this.lovelace.rawConfig)
) {
// If the entity registry changed, ask the user if they want to refresh the config
if (
oldHass.entities !== this.hass.entities ||
oldHass.devices !== this.hass.devices || oldHass.devices !== this.hass.devices ||
oldHass.areas !== this.hass.areas || oldHass.areas !== this.hass.areas ||
oldHass.floors !== this.hass.floors) oldHass.floors !== this.hass.floors
) { ) {
this._registriesChanged(); if (this.hass.config.state === "RUNNING") {
this._askRefreshConfig();
}
}
// If ha started, refresh the config
if (
this.hass.config.state === "RUNNING" &&
oldHass.config.state !== "RUNNING"
) {
this._refreshConfig();
}
} }
} }
private _registriesChanged = () => { private _askRefreshConfig = () => {
if (this.lovelace && isStrategyDashboard(this.lovelace.rawConfig)) {
showToast(this, { showToast(this, {
message: this.hass!.localize("ui.panel.lovelace.changed_toast.message"), message: this.hass!.localize("ui.panel.lovelace.changed_toast.message"),
action: { action: {
@ -208,7 +223,6 @@ export class LovelacePanel extends LitElement {
id: "entity-registry-changed", id: "entity-registry-changed",
dismissable: false, dismissable: false,
}); });
}
}; };
private async _refreshConfig() { private async _refreshConfig() {