From c74d59dfc667ee502e85a187eb17cb996703a8fc Mon Sep 17 00:00:00 2001 From: Wendelin Date: Tue, 25 Nov 2025 16:56:53 +0100 Subject: [PATCH] Use feature flag --- .../add-automation-element-dialog.ts | 35 +- .../ha-automation-add-search.ts | 328 ++++++++++-------- 2 files changed, 208 insertions(+), 155 deletions(-) diff --git a/src/panels/config/automation/add-automation-element-dialog.ts b/src/panels/config/automation/add-automation-element-dialog.ts index dabf7d2744..2e99169c0e 100644 --- a/src/panels/config/automation/add-automation-element-dialog.ts +++ b/src/panels/config/automation/add-automation-element-dialog.ts @@ -93,6 +93,7 @@ import { fetchIntegrationManifests, } from "../../../data/integration"; import type { LabelRegistryEntry } from "../../../data/label_registry"; +import { subscribeLabFeatures } from "../../../data/labs"; import { TARGET_SEPARATOR, getServicesForTarget, @@ -109,6 +110,7 @@ import { } from "../../../data/trigger"; import type { HassDialog } from "../../../dialogs/make-dialog-manager"; import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin"; +import { SubscribeMixin } from "../../../mixins/subscribe-mixin"; import type { HomeAssistant } from "../../../types"; import { isMac } from "../../../util/is_mac"; import { showToast } from "../../../util/toast"; @@ -162,7 +164,7 @@ const DYNAMIC_KEYWORDS = ["dynamicGroups", "helpers", "other"]; @customElement("add-automation-element-dialog") class DialogAddAutomationElement - extends KeyboardShortcutMixin(LitElement) + extends KeyboardShortcutMixin(SubscribeMixin(LitElement)) implements HassDialog { @property({ attribute: false }) public hass!: HomeAssistant; @@ -200,6 +202,8 @@ class DialogAddAutomationElement @state() private _loadItemsError = false; + @state() private _newTriggersAndConditions = false; + @state() private _conditionDescriptions: ConditionDescriptions = {}; @state() @@ -241,6 +245,20 @@ class DialogAddAutomationElement } } + public hassSubscribe() { + return [ + subscribeLabFeatures(this.hass!.connection, (features) => { + this._newTriggersAndConditions = + features.find( + (feature) => + feature.domain === "automation" && + feature.preview_feature === "new_triggers_conditions" + )?.enabled ?? false; + this._tab = this._newTriggersAndConditions ? "targets" : "groups"; + }), + ]; + } + public showDialog(params): void { this._params = params; @@ -293,7 +311,7 @@ class DialogAddAutomationElement this._selectedCollectionIndex = undefined; this._selectedGroup = undefined; this._selectedTarget = undefined; - this._tab = "targets"; + this._tab = this._newTriggersAndConditions ? "targets" : "groups"; this._filter = ""; this._manifests = undefined; this._domains = undefined; @@ -389,10 +407,6 @@ class DialogAddAutomationElement const automationElementType = this._params!.type; const tabButtons = [ - { - label: this.hass.localize(`ui.panel.config.automation.editor.targets`), - value: "targets", - }, { label: this.hass.localize( `ui.panel.config.automation.editor.${automationElementType}s.name` @@ -401,6 +415,13 @@ class DialogAddAutomationElement }, ]; + if (this._newTriggersAndConditions) { + tabButtons.unshift({ + label: this.hass.localize(`ui.panel.config.automation.editor.targets`), + value: "targets", + }); + } + if (this._params?.type !== "trigger") { tabButtons.push({ label: this.hass.localize("ui.panel.config.automation.editor.blocks"), @@ -442,6 +463,7 @@ class DialogAddAutomationElement ` : nothing} ${!this._filter && + tabButtons.length > 1 && (!this._narrow || (!this._selectedGroup && !this._selectedTarget)) ? html` ` diff --git a/src/panels/config/automation/add-automation-element/ha-automation-add-search.ts b/src/panels/config/automation/add-automation-element/ha-automation-add-search.ts index 96ca461935..f52c6d0f79 100644 --- a/src/panels/config/automation/add-automation-element/ha-automation-add-search.ts +++ b/src/panels/config/automation/add-automation-element/ha-automation-add-search.ts @@ -67,9 +67,7 @@ import type { } from "../add-automation-element-dialog"; import type { AddAutomationElementDialogParams } from "../show-add-automation-element-dialog"; -const SEARCH_SECTIONS = [ - "item", - "block", +const TARGET_SEARCH_SECTIONS = [ "separator", "entity", "device", @@ -97,6 +95,9 @@ export class HaAutomationAddSearch extends LitElement { @property({ type: Boolean }) public narrow = false; + @property({ type: Boolean, attribute: "new-triggers-and-conditions" }) + public newTriggersAndConditions = false; + @property({ attribute: false }) public convertToItem!: ( key: string, @@ -174,6 +175,7 @@ export class HaAutomationAddSearch extends LitElement { this.filter, this.configEntryLookup, this.items, + this.newTriggersAndConditions, this._selectedSearchSection ); @@ -188,21 +190,7 @@ export class HaAutomationAddSearch extends LitElement { } return html` - - ${SEARCH_SECTIONS.map((section) => - section === "separator" - ? html`
` - : this.addElementType !== "trigger" || section !== "block" - ? html` - ` - : nothing - )} -
+ ${this._renderSections()} ${emptySearchTranslation ? html`