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