mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
Better deal with YAML updated message (#3447)
This commit is contained in:
parent
b9afa69ee5
commit
abf70c3a3e
@ -49,8 +49,7 @@ class LovelacePanel extends LitElement {
|
|||||||
|
|
||||||
private mqls?: MediaQueryList[];
|
private mqls?: MediaQueryList[];
|
||||||
|
|
||||||
private _ignoreNextUpdateEventBecauseOfSave = false;
|
private _ignoreNextUpdateEvent = false;
|
||||||
private _ignoreUpdateUntilTime: number | undefined;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -185,14 +184,8 @@ class LovelacePanel extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _lovelaceChanged() {
|
private _lovelaceChanged() {
|
||||||
if (
|
if (this._ignoreNextUpdateEvent) {
|
||||||
this._ignoreUpdateUntilTime &&
|
this._ignoreNextUpdateEvent = false;
|
||||||
new Date().getTime() < this._ignoreUpdateUntilTime
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this._ignoreNextUpdateEventBecauseOfSave) {
|
|
||||||
this._ignoreNextUpdateEventBecauseOfSave = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showToast(this, {
|
showToast(this, {
|
||||||
@ -222,10 +215,10 @@ class LovelacePanel extends LitElement {
|
|||||||
llWindow.llConfProm = undefined;
|
llWindow.llConfProm = undefined;
|
||||||
} else {
|
} else {
|
||||||
// Refreshing a YAML config can trigger an update event. We will ignore
|
// Refreshing a YAML config can trigger an update event. We will ignore
|
||||||
// all update events for a second after we refresh, as we already have
|
// all update events while fetching the config and for 2 seconds after the cnofig is back.
|
||||||
// the latest config in that case.
|
// We ignore because we already have the latest config.
|
||||||
if (this.lovelace && this.lovelace.mode === "yaml") {
|
if (this.lovelace && this.lovelace.mode === "yaml") {
|
||||||
this._ignoreUpdateUntilTime = new Date().getTime() + 1000;
|
this._ignoreNextUpdateEvent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
confProm = fetchConfig(this.hass!.connection, forceDiskRefresh);
|
confProm = fetchConfig(this.hass!.connection, forceDiskRefresh);
|
||||||
@ -243,6 +236,13 @@ class LovelacePanel extends LitElement {
|
|||||||
}
|
}
|
||||||
conf = await generateLovelaceConfigFromHass(this.hass!);
|
conf = await generateLovelaceConfigFromHass(this.hass!);
|
||||||
confMode = "generated";
|
confMode = "generated";
|
||||||
|
} finally {
|
||||||
|
// Ignore updates for another 2 seconds.
|
||||||
|
if (this.lovelace && this.lovelace.mode === "yaml") {
|
||||||
|
setTimeout(() => {
|
||||||
|
this._ignoreNextUpdateEvent = false;
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._state = "loaded";
|
this._state = "loaded";
|
||||||
@ -279,7 +279,7 @@ class LovelacePanel extends LitElement {
|
|||||||
config: newConfig,
|
config: newConfig,
|
||||||
mode: "storage",
|
mode: "storage",
|
||||||
});
|
});
|
||||||
this._ignoreNextUpdateEventBecauseOfSave = true;
|
this._ignoreNextUpdateEvent = true;
|
||||||
await saveConfig(this.hass!, newConfig);
|
await saveConfig(this.hass!, newConfig);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
|
Loading…
x
Reference in New Issue
Block a user