1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-02 00:27:49 +01:00

Move Device and Entity triggers and conditions to Generic group (#30185)

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Aidan Timson
2026-03-18 08:07:27 +00:00
committed by GitHub
parent b1921d1b66
commit 3370bfa9dd
2 changed files with 57 additions and 16 deletions

View File

@@ -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
<wa-divider></wa-divider>`
: nothing}
${collections.map(
(collection, index) => html`
(collection) => html`
${collection.titleKey && collection.groups.length
? html`<ha-section-title>
${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),

View File

@@ -4872,6 +4872,7 @@
"none_entities": "No entities",
"template": "Template"
},
"generic": "Generic",
"triggers": {
"name": "Triggers",
"header": "When",