Ignore LL updates for a second in YAML mode (#3433)

This commit is contained in:
Paulus Schoutsen 2019-07-26 20:30:54 -07:00 committed by GitHub
parent dcfed5d7e1
commit 689e37782e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,7 +49,8 @@ class LovelacePanel extends LitElement {
private mqls?: MediaQueryList[]; private mqls?: MediaQueryList[];
private _saving: boolean = false; private _ignoreNextUpdateEventBecauseOfSave = false;
private _ignoreUpdateUntilTime: number | undefined;
constructor() { constructor() {
super(); super();
@ -184,19 +185,25 @@ class LovelacePanel extends LitElement {
} }
private _lovelaceChanged() { private _lovelaceChanged() {
if (this._saving) { if (
this._saving = false; this._ignoreUpdateUntilTime &&
} else { new Date().getTime() < this._ignoreUpdateUntilTime
showToast(this, { ) {
message: this.hass!.localize("ui.panel.lovelace.changed_toast.message"), return;
action: {
action: () => this._fetchConfig(false),
text: this.hass!.localize("ui.panel.lovelace.changed_toast.refresh"),
},
duration: 0,
dismissable: false,
});
} }
if (this._ignoreNextUpdateEventBecauseOfSave) {
this._ignoreNextUpdateEventBecauseOfSave = false;
return;
}
showToast(this, {
message: this.hass!.localize("ui.panel.lovelace.changed_toast.message"),
action: {
action: () => this._fetchConfig(false),
text: this.hass!.localize("ui.panel.lovelace.changed_toast.refresh"),
},
duration: 0,
dismissable: false,
});
} }
private _forceFetchConfig() { private _forceFetchConfig() {
@ -214,6 +221,13 @@ class LovelacePanel extends LitElement {
confProm = llWindow.llConfProm; confProm = llWindow.llConfProm;
llWindow.llConfProm = undefined; llWindow.llConfProm = undefined;
} else { } else {
// 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
// the latest config in that case.
if (this.lovelace && this.lovelace.mode === "yaml") {
this._ignoreUpdateUntilTime = new Date().getTime() + 1000;
}
confProm = fetchConfig(this.hass!.connection, forceDiskRefresh); confProm = fetchConfig(this.hass!.connection, forceDiskRefresh);
} }
@ -265,7 +279,7 @@ class LovelacePanel extends LitElement {
config: newConfig, config: newConfig,
mode: "storage", mode: "storage",
}); });
this._saving = true; this._ignoreNextUpdateEventBecauseOfSave = true;
await saveConfig(this.hass!, newConfig); await saveConfig(this.hass!, newConfig);
} catch (err) { } catch (err) {
// tslint:disable-next-line // tslint:disable-next-line