mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Reuse flatten logic for trigger ids condition (#22136)
This commit is contained in:
parent
7ee5db2be5
commit
ead54e445f
@ -442,7 +442,7 @@ export const migrateAutomationTrigger = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const flattenTriggers = (
|
export const flattenTriggers = (
|
||||||
triggers: undefined | Trigger | (Trigger | TriggerList)[]
|
triggers: undefined | Trigger | Trigger[]
|
||||||
): Trigger[] => {
|
): Trigger[] => {
|
||||||
if (!triggers) {
|
if (!triggers) {
|
||||||
return [];
|
return [];
|
||||||
@ -453,7 +453,7 @@ export const flattenTriggers = (
|
|||||||
ensureArray(triggers).forEach((t) => {
|
ensureArray(triggers).forEach((t) => {
|
||||||
if ("triggers" in t) {
|
if ("triggers" in t) {
|
||||||
if (t.triggers) {
|
if (t.triggers) {
|
||||||
flatTriggers.push(...ensureArray(t.triggers));
|
flatTriggers.push(...flattenTriggers(t.triggers));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
flatTriggers.push(t);
|
flatTriggers.push(t);
|
||||||
|
@ -8,26 +8,19 @@ import { fireEvent } from "../../../../../common/dom/fire_event";
|
|||||||
import "../../../../../components/ha-form/ha-form";
|
import "../../../../../components/ha-form/ha-form";
|
||||||
import type { SchemaUnion } from "../../../../../components/ha-form/types";
|
import type { SchemaUnion } from "../../../../../components/ha-form/types";
|
||||||
import "../../../../../components/ha-select";
|
import "../../../../../components/ha-select";
|
||||||
import type {
|
import {
|
||||||
AutomationConfig,
|
flattenTriggers,
|
||||||
Trigger,
|
type AutomationConfig,
|
||||||
TriggerCondition,
|
type Trigger,
|
||||||
|
type TriggerCondition,
|
||||||
} from "../../../../../data/automation";
|
} from "../../../../../data/automation";
|
||||||
import type { HomeAssistant } from "../../../../../types";
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
|
|
||||||
const getTriggersIds = (triggers: Trigger[]): string[] => {
|
const getTriggersIds = (triggers: Trigger[]): string[] => {
|
||||||
const ids: Set<string> = new Set();
|
const triggerIds = flattenTriggers(triggers)
|
||||||
triggers.forEach((trigger) => {
|
.map((t) => ("id" in t ? t.id : undefined))
|
||||||
if ("triggers" in trigger) {
|
.filter(Boolean) as string[];
|
||||||
const newIds = getTriggersIds(ensureArray(trigger.triggers));
|
return Array.from(new Set(triggerIds));
|
||||||
for (const id of newIds) {
|
|
||||||
ids.add(id);
|
|
||||||
}
|
|
||||||
} else if (trigger.id) {
|
|
||||||
ids.add(trigger.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return Array.from(ids);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@customElement("ha-automation-condition-trigger")
|
@customElement("ha-automation-condition-trigger")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user