From e6862daa38f160631ae599fe1a982dc3cbfb1cba Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 6 Sep 2022 09:33:53 -0400 Subject: [PATCH] Avoid script editor dirty on load (#13619) --- src/panels/config/script/ha-script-editor.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/panels/config/script/ha-script-editor.ts b/src/panels/config/script/ha-script-editor.ts index acfee65f3f..44a333f885 100644 --- a/src/panels/config/script/ha-script-editor.ts +++ b/src/panels/config/script/ha-script-editor.ts @@ -536,6 +536,12 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { } private _modeChanged(mode) { + const curMode = this._config!.mode || MODES[0]; + + if (mode === curMode) { + return; + } + this._config = { ...this._config!, mode }; if (!isMaxMode(mode)) { delete this._config.max; @@ -575,6 +581,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { ev.stopPropagation(); const values = ev.detail.value as any; const currentId = this._entityId; + let changed = false; for (const key of Object.keys(values)) { if (key === "sequence") { @@ -590,6 +597,8 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { continue; } + changed = true; + switch (key) { case "id": this._idChanged(value); @@ -603,14 +612,17 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { } if (values[key] === undefined) { - delete this._config![key]; - this._config = { ...this._config! }; + const newConfig = { ...this._config! }; + delete newConfig![key]; + this._config = newConfig; } else { this._config = { ...this._config!, [key]: value }; } } - this._dirty = true; + if (changed) { + this._dirty = true; + } } private _configChanged(ev) {