diff --git a/src/panels/config/automation/add-automation-element-dialog.ts b/src/panels/config/automation/add-automation-element-dialog.ts index 5af2110bb1..aec586a08c 100644 --- a/src/panels/config/automation/add-automation-element-dialog.ts +++ b/src/panels/config/automation/add-automation-element-dialog.ts @@ -140,6 +140,12 @@ const TYPES = { }, }; +export interface CollectionGroup { + collectionIndex: number; + titleKey?: LocalizeKeys; + groups: AddAutomationElementListItem[]; +} + export interface AutomationItemComboBoxItem extends PickerComboBoxItem { renderedIcon?: TemplateResult; type: "trigger" | "condition" | "action" | "block"; @@ -169,6 +175,8 @@ const ENTITY_DOMAINS_MAIN = new Set(["notify"]); const DYNAMIC_KEYWORDS = ["dynamicGroups", "helpers", "other"]; +const GENERIC_GROUPS = new Set(["device", "entity"]); + @customElement("add-automation-element-dialog") class DialogAddAutomationElement extends KeyboardShortcutMixin(LitElement) @@ -668,7 +676,7 @@ class DialogAddAutomationElement ` : nothing} ${collections.map( - (collection, index) => html` + (collection) => html` ${collection.titleKey && collection.groups.length ? html` ${this.hass.localize(collection.titleKey)} @@ -682,7 +690,7 @@ class DialogAddAutomationElement interactive type="button" .value=${item.key} - .index=${index} + .index=${collection.collectionIndex} @click=${this._groupSelected} class=${item.key === this._selectedGroup ? "selected" @@ -906,11 +914,12 @@ class DialogAddAutomationElement collectionIndex?: number ): AutomationElementGroup => { if (group && collectionIndex !== undefined) { - return ( - TYPES[type].collections[collectionIndex].groups[group].members || { - [group]: {}, - } - ); + const selectedGroup = + TYPES[type].collections[collectionIndex]?.groups[group] ?? + TYPES[type].collections.find((collection) => group in collection.groups) + ?.groups[group]; + + return selectedGroup?.members || { [group]: selectedGroup || {} }; } return TYPES[type].collections.reduce( @@ -960,13 +969,10 @@ class DialogAddAutomationElement triggerDescriptions: TriggerDescriptions, conditionDescriptions: ConditionDescriptions, manifests?: DomainManifestLookup - ): { - titleKey?: LocalizeKeys; - groups: AddAutomationElementListItem[]; - }[] => { - const generatedCollections: any = []; + ): CollectionGroup[] => { + const generatedCollections: CollectionGroup[] = []; - collections.forEach((collection) => { + collections.forEach((collection, index) => { let collectionGroups = Object.entries(collection.groups); const groups: AddAutomationElementListItem[] = []; @@ -1048,6 +1054,7 @@ class DialogAddAutomationElement ); generatedCollections.push({ + collectionIndex: index, titleKey: collection.titleKey, groups: groups.sort((a, b) => { // make sure device is always on top @@ -1061,7 +1068,40 @@ class DialogAddAutomationElement }), }); }); - return generatedCollections; + + return !["trigger", "condition"].includes(type) + ? generatedCollections + : generatedCollections.flatMap( + (collection: CollectionGroup): CollectionGroup[] => { + const genericGroups = collection.groups.filter((group) => + GENERIC_GROUPS.has(group.key) + ); + + const mainGroups = collection.groups.filter( + (group) => !GENERIC_GROUPS.has(group.key) + ); + + return [ + ...(mainGroups.length + ? [ + { + ...collection, + groups: mainGroups, + }, + ] + : []), + ...(genericGroups.length + ? [ + { + collectionIndex: collection.collectionIndex, + titleKey: "ui.panel.config.automation.editor.generic", + groups: genericGroups, + } satisfies CollectionGroup, + ] + : []), + ]; + } + ); } ); @@ -2127,7 +2167,7 @@ class DialogAddAutomationElement ha-dialog { --dialog-content-padding: 0; --ha-dialog-min-height: min( - 800px, + 920px, calc( 100vh - max( var(--safe-area-inset-bottom), @@ -2136,7 +2176,7 @@ class DialogAddAutomationElement ) ); --ha-dialog-min-height: min( - 800px, + 920px, calc( 100dvh - max( var(--safe-area-inset-bottom), diff --git a/src/translations/en.json b/src/translations/en.json index 1f137f1f2f..f3ac9ea7a8 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4872,6 +4872,7 @@ "none_entities": "No entities", "template": "Template" }, + "generic": "Generic", "triggers": { "name": "Triggers", "header": "When",