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 0368fae41e26..29e304208d62 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 @@ -12,7 +12,10 @@ import "../../../../components/ha-textfield"; import { HassDialog } from "../../../../dialogs/make-dialog-manager"; import { haStyle, haStyleDialog } from "../../../../resources/styles"; import type { HomeAssistant } from "../../../../types"; -import type { AutomationRenameDialogParams } from "./show-dialog-automation-rename"; +import type { + AutomationRenameDialogParams, + ScriptRenameDialogParams, +} from "./show-dialog-automation-rename"; @customElement("ha-dialog-automation-rename") class DialogAutomationRename extends LitElement implements HassDialog { @@ -22,7 +25,7 @@ class DialogAutomationRename extends LitElement implements HassDialog { @state() private _error?: string; - private _params!: AutomationRenameDialogParams; + private _params!: AutomationRenameDialogParams | ScriptRenameDialogParams; private _newName?: string; @@ -30,10 +33,12 @@ class DialogAutomationRename extends LitElement implements HassDialog { private _newDescription?: string; - public showDialog(params: AutomationRenameDialogParams): void { + public showDialog( + params: AutomationRenameDialogParams | ScriptRenameDialogParams + ): void { this._opened = true; this._params = params; - this._newIcon = params.icon; + this._newIcon = "icon" in params.config ? params.config.icon : undefined; this._newName = params.config.alias || this.hass.localize("ui.panel.config.automation.editor.default_name"); @@ -88,22 +93,24 @@ class DialogAutomationRename extends LitElement implements HassDialog { @input=${this._valueChanged} > - ${this._params.supportsIcon - ? html` - - - ` + + + + ` : nothing} export interface AutomationRenameDialogParams { config: AutomationConfig; - supportsIcon: boolean; - updateConfig: (config: AutomationConfig, icon: string | undefined) => void; - icon: string | undefined; + domain: "automation"; + updateConfig: (config: AutomationConfig) => void; onClose: () => void; } -export interface ScriptnRenameDialogParams { +export interface ScriptRenameDialogParams { config: ScriptConfig; - supportsIcon: boolean; + domain: "script"; updateConfig: (config: ScriptConfig) => void; - icon: string | undefined; onClose: () => void; } export const showAutomationRenameDialog = ( element: HTMLElement, - dialogParams: AutomationRenameDialogParams | ScriptnRenameDialogParams + dialogParams: AutomationRenameDialogParams | ScriptRenameDialogParams ): void => { fireEvent(element, "show-dialog", { dialogTag: "ha-dialog-automation-rename", diff --git a/src/panels/config/automation/ha-automation-editor.ts b/src/panels/config/automation/ha-automation-editor.ts index 65dd0a3e5935..47060401487a 100644 --- a/src/panels/config/automation/ha-automation-editor.ts +++ b/src/panels/config/automation/ha-automation-editor.ts @@ -53,7 +53,6 @@ import { UNAVAILABLE } from "../../../data/entity"; import { EntityRegistryDisplayEntry, fetchEntityRegistry, - updateEntityRegistryEntry, } from "../../../data/entity_registry"; import { showAlertDialog, @@ -104,8 +103,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { @state() private _config?: AutomationConfig; - @state() private _icon?: string; - @state() private _dirty = false; @state() private _errors?: string; @@ -472,12 +469,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { sub(this._config) ); } - - if (changedProps.has("hass")) { - if (this._entry && !this._dirty) { - this._icon = this._entry.icon; - } - } } private _setEntityId() { @@ -485,10 +476,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { (entity: AutomationEntity) => entity.attributes.id === this.automationId ); this._entityId = automation?.entity_id; - - if (this._entry) { - this._icon = this._entry.icon; - } } private async _checkValidation() { @@ -709,11 +696,9 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { return new Promise((resolve) => { showAutomationRenameDialog(this, { config: this._config!, - icon: this._icon, - supportsIcon: this._entry !== undefined, - updateConfig: (config, icon) => { + domain: "automation", + updateConfig: (config) => { this._config = config; - this._icon = icon; this._dirty = true; this.requestUpdate(); resolve(true); @@ -750,11 +735,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { this._validationErrors = undefined; try { await saveAutomationConfig(this.hass, id, this._config!); - if (this._entry && this._entry.icon !== this._icon) { - await updateEntityRegistryEntry(this.hass, this._entry.entity_id, { - icon: this._icon, - }); - } } catch (errors: any) { this._errors = errors.body.message || errors.error || errors.body; showToast(this, { diff --git a/src/panels/config/script/ha-script-editor.ts b/src/panels/config/script/ha-script-editor.ts index df47c2b22d30..68f98d4e3277 100644 --- a/src/panels/config/script/ha-script-editor.ts +++ b/src/panels/config/script/ha-script-editor.ts @@ -33,15 +33,14 @@ import "../../../components/ha-button-menu"; import "../../../components/ha-fab"; import "../../../components/ha-icon-button"; +import "../../../components/ha-list-item"; import "../../../components/ha-svg-icon"; import "../../../components/ha-yaml-editor"; -import "../../../components/ha-list-item"; import { validateConfig } from "../../../data/config"; import { UNAVAILABLE } from "../../../data/entity"; import { EntityRegistryDisplayEntry, EntityRegistryEntry, - updateEntityRegistryEntry, } from "../../../data/entity_registry"; import { ScriptConfig, @@ -54,6 +53,7 @@ import { triggerScript, } from "../../../data/script"; import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box"; +import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog"; import "../../../layouts/hass-subpage"; import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin"; import { haStyle } from "../../../resources/styles"; @@ -64,7 +64,6 @@ import { showAutomationRenameDialog } from "../automation/automation-rename-dial import "./blueprint-script-editor"; import "./manual-script-editor"; import type { HaManualScriptEditor } from "./manual-script-editor"; -import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog"; export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { @property({ attribute: false }) public hass!: HomeAssistant; @@ -85,8 +84,6 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { @state() private _idError = false; - @state() private _icon?: string; - @state() private _dirty = false; @state() private _errors?: string; @@ -419,12 +416,6 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { this._dirty = false; this._readOnly = true; } - - if (changedProps.has("hass")) { - if (this._entry && !this._dirty) { - this._icon = this._entry.icon; - } - } } private _setEntityId(id?: string) { @@ -434,10 +425,6 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { } else { this._idError = false; } - - if (this._entry) { - this._icon = this._entry.icon; - } } private async _checkValidation() { @@ -674,8 +661,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { return new Promise((resolve) => { showAutomationRenameDialog(this, { config: this._config!, - icon: this._icon, - supportsIcon: this._entry !== undefined, + domain: "script", updateConfig: (config) => { this._config = config; this._dirty = true; @@ -734,11 +720,6 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { "config/script/config/" + id, this._config ); - if (this._entry && this._entry.icon !== this._icon) { - await updateEntityRegistryEntry(this.hass, this._entry.entity_id, { - icon: this._icon, - }); - } } catch (errors: any) { this._errors = errors.body.message || errors.error || errors.body; showToast(this, {