diff --git a/src/panels/config/automation/action/ha-automation-action.ts b/src/panels/config/automation/action/ha-automation-action.ts index e41f9e500f..678f829bcb 100644 --- a/src/panels/config/automation/action/ha-automation-action.ts +++ b/src/panels/config/automation/action/ha-automation-action.ts @@ -235,7 +235,7 @@ export default class HaAutomationAction extends LitElement { private async _actionAdded(ev: CustomEvent): Promise { ev.stopPropagation(); const { index, data } = ev.detail; - const actions = [ + let actions = [ ...this.actions.slice(0, index), data, ...this.actions.slice(index), @@ -243,7 +243,15 @@ export default class HaAutomationAction extends LitElement { // Add action locally to avoid UI jump this.actions = actions; await nextRender(); - fireEvent(this, "value-changed", { value: this.actions }); + if (this.actions !== actions) { + // Ensure action is added even after update + actions = [ + ...this.actions.slice(0, index), + data, + ...this.actions.slice(index), + ]; + } + fireEvent(this, "value-changed", { value: actions }); } private async _actionRemoved(ev: CustomEvent): Promise { diff --git a/src/panels/config/automation/condition/ha-automation-condition.ts b/src/panels/config/automation/condition/ha-automation-condition.ts index f1557a7956..46e18ab00d 100644 --- a/src/panels/config/automation/condition/ha-automation-condition.ts +++ b/src/panels/config/automation/condition/ha-automation-condition.ts @@ -258,7 +258,7 @@ export default class HaAutomationCondition extends LitElement { private async _conditionAdded(ev: CustomEvent): Promise { ev.stopPropagation(); const { index, data } = ev.detail; - const conditions = [ + let conditions = [ ...this.conditions.slice(0, index), data, ...this.conditions.slice(index), @@ -266,7 +266,15 @@ export default class HaAutomationCondition extends LitElement { // Add condition locally to avoid UI jump this.conditions = conditions; await nextRender(); - fireEvent(this, "value-changed", { value: this.conditions }); + if (this.conditions !== conditions) { + // Ensure condition is added even after update + conditions = [ + ...this.conditions.slice(0, index), + data, + ...this.conditions.slice(index), + ]; + } + fireEvent(this, "value-changed", { value: conditions }); } private async _conditionRemoved(ev: CustomEvent): Promise { diff --git a/src/panels/config/automation/trigger/ha-automation-trigger.ts b/src/panels/config/automation/trigger/ha-automation-trigger.ts index cc6219d0cc..7e7fefd79e 100644 --- a/src/panels/config/automation/trigger/ha-automation-trigger.ts +++ b/src/panels/config/automation/trigger/ha-automation-trigger.ts @@ -220,7 +220,7 @@ export default class HaAutomationTrigger extends LitElement { private async _triggerAdded(ev: CustomEvent): Promise { ev.stopPropagation(); const { index, data } = ev.detail; - const triggers = [ + let triggers = [ ...this.triggers.slice(0, index), data, ...this.triggers.slice(index), @@ -228,7 +228,15 @@ export default class HaAutomationTrigger extends LitElement { // Add trigger locally to avoid UI jump this.triggers = triggers; await nextRender(); - fireEvent(this, "value-changed", { value: this.triggers }); + if (this.triggers !== triggers) { + // Ensure trigger is added even after update + triggers = [ + ...this.triggers.slice(0, index), + data, + ...this.triggers.slice(index), + ]; + } + fireEvent(this, "value-changed", { value: triggers }); } private async _triggerRemoved(ev: CustomEvent): Promise {