From 5699c526c0c05f852793754217c80bfd36913b20 Mon Sep 17 00:00:00 2001 From: karwosts Date: Mon, 13 May 2024 08:42:41 -0700 Subject: [PATCH] review feedback --- .../dialog-automation-mode.ts | 2 +- .../show-dialog-automation-mode.ts | 4 +- .../dialog-automation-rename.ts | 2 +- .../show-dialog-automation-rename.ts | 4 +- .../config/automation/ha-automation-editor.ts | 4 +- src/panels/config/script/ha-script-editor.ts | 40 +++++-------------- 6 files changed, 17 insertions(+), 39 deletions(-) diff --git a/src/panels/config/automation/automation-mode-dialog/dialog-automation-mode.ts b/src/panels/config/automation/automation-mode-dialog/dialog-automation-mode.ts index 54175de1083c..ba624d072183 100644 --- a/src/panels/config/automation/automation-mode-dialog/dialog-automation-mode.ts +++ b/src/panels/config/automation/automation-mode-dialog/dialog-automation-mode.ts @@ -138,7 +138,7 @@ class DialogAutomationMode extends LitElement implements HassDialog { } private _save(): void { - this._params.updateAutomation({ + this._params.updateConfig({ ...this._params.config, mode: this._newMode, max: this._newMax, diff --git a/src/panels/config/automation/automation-mode-dialog/show-dialog-automation-mode.ts b/src/panels/config/automation/automation-mode-dialog/show-dialog-automation-mode.ts index 2e26b4b5758a..0d25fea5d2f3 100644 --- a/src/panels/config/automation/automation-mode-dialog/show-dialog-automation-mode.ts +++ b/src/panels/config/automation/automation-mode-dialog/show-dialog-automation-mode.ts @@ -7,13 +7,13 @@ export const loadAutomationModeDialog = () => export interface AutomationModeDialog { config: AutomationConfig; - updateAutomation: (config: AutomationConfig) => void; + updateConfig: (config: AutomationConfig) => void; onClose: () => void; } export interface ScriptModeDialog { config: ScriptConfig; - updateAutomation: (config: ScriptConfig) => void; + updateConfig: (config: ScriptConfig) => void; onClose: () => void; } diff --git a/src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts b/src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts index f39223cfad50..7d869fd5b9ef 100644 --- a/src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts +++ b/src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts @@ -124,7 +124,7 @@ class DialogAutomationRename extends LitElement implements HassDialog { this._error = "Name is required"; return; } - this._params.updateAutomation({ + this._params.updateConfig({ ...this._params.config, alias: this._newName, description: this._newDescription, diff --git a/src/panels/config/automation/automation-rename-dialog/show-dialog-automation-rename.ts b/src/panels/config/automation/automation-rename-dialog/show-dialog-automation-rename.ts index 11b10cf1c1da..9c0b46435654 100644 --- a/src/panels/config/automation/automation-rename-dialog/show-dialog-automation-rename.ts +++ b/src/panels/config/automation/automation-rename-dialog/show-dialog-automation-rename.ts @@ -7,13 +7,13 @@ export const loadAutomationRenameDialog = () => export interface AutomationRenameDialog { config: AutomationConfig; - updateAutomation: (config: AutomationConfig) => void; + updateConfig: (config: AutomationConfig) => void; onClose: () => void; } export interface ScriptRenameDialog { config: ScriptConfig; - updateAutomation: (config: ScriptConfig) => void; + updateConfig: (config: ScriptConfig) => void; onClose: () => void; } diff --git a/src/panels/config/automation/ha-automation-editor.ts b/src/panels/config/automation/ha-automation-editor.ts index 54c51b37c81e..22793380104e 100644 --- a/src/panels/config/automation/ha-automation-editor.ts +++ b/src/panels/config/automation/ha-automation-editor.ts @@ -688,7 +688,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { return new Promise((resolve) => { showAutomationRenameDialog(this, { config: this._config!, - updateAutomation: (config) => { + updateConfig: (config) => { this._config = config; this._dirty = true; this.requestUpdate(); @@ -703,7 +703,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { return new Promise((resolve) => { showAutomationModeDialog(this, { config: this._config!, - updateAutomation: (config) => { + updateConfig: (config) => { this._config = config; this._dirty = true; this.requestUpdate(); diff --git a/src/panels/config/script/ha-script-editor.ts b/src/panels/config/script/ha-script-editor.ts index c0f7785bfcda..0d8d3d0841ba 100644 --- a/src/panels/config/script/ha-script-editor.ts +++ b/src/panels/config/script/ha-script-editor.ts @@ -186,7 +186,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { ${this.hass.localize( @@ -555,29 +555,6 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { } } - private updateEntityId( - newId: string | undefined, - newAlias: string | undefined - ) { - const currentAlias = this._config?.alias ?? ""; - const currentEntityId = this._entityId ?? ""; - - if (newId !== this._entityId) { - this._setEntityId(newId || undefined); - return; - } - - const currentComputedEntity = this._computeEntityIdFromAlias(currentAlias); - - if (currentComputedEntity === currentEntityId || !this._entityId) { - const newComputedId = newAlias - ? this._computeEntityIdFromAlias(newAlias) - : undefined; - - this._setEntityId(newComputedId); - } - } - private _addFields() { if ("fields" in this._config!) { return; @@ -673,11 +650,11 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { this._mode = "yaml"; } - private async _promptAutomationAlias(): Promise { + private async _promptScriptAlias(): Promise { return new Promise((resolve) => { showAutomationRenameDialog(this, { config: this._config!, - updateAutomation: (config) => { + updateConfig: (config) => { this._config = config; this._dirty = true; this.requestUpdate(); @@ -688,11 +665,11 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { }); } - private async _promptAutomationMode(): Promise { + private async _promptScriptMode(): Promise { return new Promise((resolve) => { showAutomationModeDialog(this, { config: this._config!, - updateAutomation: (config) => { + updateConfig: (config) => { this._config = config; this._dirty = true; this.requestUpdate(); @@ -720,11 +697,12 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { } if (!this.scriptId) { - const saved = await this._promptAutomationAlias(); + const saved = await this._promptScriptAlias(); if (!saved) { return; } - this.updateEntityId(undefined, this._config!.alias); + const entityId = this._computeEntityIdFromAlias(this._config!.alias); + this._setEntityId(entityId); } const id = this.scriptId || this._entityId || Date.now();