mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Fixes for trace viewer for nested triggers feature (#21765)
This commit is contained in:
parent
48887f2066
commit
915036006d
@ -22,7 +22,7 @@ import { LitElement, PropertyValues, css, html, nothing } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { ensureArray } from "../../common/array/ensure-array";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { Condition, Trigger } from "../../data/automation";
|
||||
import { Condition, Trigger, flattenTriggers } from "../../data/automation";
|
||||
import {
|
||||
Action,
|
||||
ChooseAction,
|
||||
@ -572,8 +572,8 @@ export class HatScriptGraph extends LitElement {
|
||||
const paths = Object.keys(this.trackedNodes);
|
||||
const trigger_nodes =
|
||||
"trigger" in this.trace.config
|
||||
? ensureArray(this.trace.config.trigger).map((trigger, i) =>
|
||||
this.render_trigger(trigger, i)
|
||||
? flattenTriggers(ensureArray(this.trace.config.trigger)).map(
|
||||
(trigger, i) => this.render_trigger(trigger, i)
|
||||
)
|
||||
: undefined;
|
||||
try {
|
||||
|
@ -3,6 +3,7 @@ import {
|
||||
HassEntityBase,
|
||||
} from "home-assistant-js-websocket";
|
||||
import { navigate } from "../common/navigate";
|
||||
import { ensureArray } from "../common/array/ensure-array";
|
||||
import { Context, HomeAssistant } from "../types";
|
||||
import { BlueprintInput } from "./blueprint";
|
||||
import { DeviceCondition, DeviceTrigger } from "./device_automation";
|
||||
@ -62,6 +63,10 @@ export interface ContextConstraint {
|
||||
user_id?: string | string[];
|
||||
}
|
||||
|
||||
export interface TriggerList {
|
||||
triggers: Trigger | Trigger[] | undefined;
|
||||
}
|
||||
|
||||
export interface BaseTrigger {
|
||||
alias?: string;
|
||||
platform: string;
|
||||
@ -373,6 +378,27 @@ export const normalizeAutomationConfig = <
|
||||
return config;
|
||||
};
|
||||
|
||||
export const flattenTriggers = (
|
||||
triggers: undefined | (Trigger | TriggerList)[]
|
||||
): Trigger[] => {
|
||||
if (!triggers) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const flatTriggers: Trigger[] = [];
|
||||
|
||||
triggers.forEach((t) => {
|
||||
if ("triggers" in t) {
|
||||
if (t.triggers) {
|
||||
flatTriggers.push(...ensureArray(t.triggers));
|
||||
}
|
||||
} else {
|
||||
flatTriggers.push(t);
|
||||
}
|
||||
});
|
||||
return flatTriggers;
|
||||
};
|
||||
|
||||
export const showAutomationEditor = (data?: Partial<AutomationConfig>) => {
|
||||
initialAutomationEditorData = data;
|
||||
navigate("/config/automation/edit/new");
|
||||
|
@ -3,6 +3,7 @@ import { Context, HomeAssistant } from "../types";
|
||||
import {
|
||||
BlueprintAutomationConfig,
|
||||
ManualAutomationConfig,
|
||||
flattenTriggers,
|
||||
} from "./automation";
|
||||
import { BlueprintScriptConfig, ScriptConfig } from "./script";
|
||||
|
||||
@ -190,7 +191,11 @@ export const getDataFromPath = (
|
||||
if (!tempResult && raw === "sequence") {
|
||||
continue;
|
||||
}
|
||||
result = tempResult;
|
||||
if (raw === "trigger") {
|
||||
result = flattenTriggers(tempResult);
|
||||
} else {
|
||||
result = tempResult;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user