mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Handle configurations that don't wrap their action sequences in arrays (#8798)
This commit is contained in:
parent
a0b5bc5456
commit
82ad5c103d
@ -1,5 +1,7 @@
|
|||||||
|
type NonUndefined<T> = T extends undefined ? never : T;
|
||||||
|
|
||||||
export function ensureArray(value: undefined): undefined;
|
export function ensureArray(value: undefined): undefined;
|
||||||
export function ensureArray<T>(value: T | T[]): T[];
|
export function ensureArray<T>(value: T | T[]): NonUndefined<T>[];
|
||||||
export function ensureArray(value) {
|
export function ensureArray(value) {
|
||||||
if (value === undefined || Array.isArray(value)) {
|
if (value === undefined || Array.isArray(value)) {
|
||||||
return value;
|
return value;
|
||||||
|
@ -177,7 +177,7 @@ class HatScriptGraph extends LitElement {
|
|||||||
track: trace !== undefined && trace[0].result?.choice === i,
|
track: trace !== undefined && trace[0].result?.choice === i,
|
||||||
})}
|
})}
|
||||||
></hat-graph-node>
|
></hat-graph-node>
|
||||||
${branch.sequence.map((action, j) =>
|
${ensureArray(branch.sequence).map((action, j) =>
|
||||||
this.render_node(action, `${branch_path}/sequence/${j}`)
|
this.render_node(action, `${branch_path}/sequence/${j}`)
|
||||||
)}
|
)}
|
||||||
</hat-graph>
|
</hat-graph>
|
||||||
@ -192,7 +192,7 @@ class HatScriptGraph extends LitElement {
|
|||||||
trace !== undefined && trace[0].result?.choice === "default",
|
trace !== undefined && trace[0].result?.choice === "default",
|
||||||
})}
|
})}
|
||||||
></hat-graph-node>
|
></hat-graph-node>
|
||||||
${config.default?.map((action, i) =>
|
${ensureArray(config.default)?.map((action, i) =>
|
||||||
this.render_node(action, `${path}/default/${i}`)
|
this.render_node(action, `${path}/default/${i}`)
|
||||||
)}
|
)}
|
||||||
</hat-graph>
|
</hat-graph>
|
||||||
@ -319,7 +319,7 @@ class HatScriptGraph extends LitElement {
|
|||||||
.badge=${repeats}
|
.badge=${repeats}
|
||||||
></hat-graph-node>
|
></hat-graph-node>
|
||||||
<hat-graph>
|
<hat-graph>
|
||||||
${node.repeat.sequence.map((action, i) =>
|
${ensureArray(node.repeat.sequence).map((action, i) =>
|
||||||
this.render_node(action, `${path}/repeat/sequence/${i}`)
|
this.render_node(action, `${path}/repeat/sequence/${i}`)
|
||||||
)}
|
)}
|
||||||
</hat-graph>
|
</hat-graph>
|
||||||
@ -421,43 +421,52 @@ class HatScriptGraph extends LitElement {
|
|||||||
return this.render_trigger(trigger, i);
|
return this.render_trigger(trigger, i);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return html`
|
try {
|
||||||
<hat-graph class="parent">
|
return html`
|
||||||
<div></div>
|
<hat-graph class="parent">
|
||||||
<hat-graph
|
<div></div>
|
||||||
branching
|
<hat-graph
|
||||||
id="trigger"
|
branching
|
||||||
.short=${trigger_nodes.length < 2}
|
id="trigger"
|
||||||
.track_start=${track_path}
|
.short=${trigger_nodes.length < 2}
|
||||||
.track_end=${track_path}
|
.track_start=${track_path}
|
||||||
>
|
.track_end=${track_path}
|
||||||
${trigger_nodes}
|
>
|
||||||
</hat-graph>
|
${trigger_nodes}
|
||||||
<hat-graph id="condition">
|
</hat-graph>
|
||||||
${ensureArray(this.trace.config.condition)?.map((condition, i) =>
|
<hat-graph id="condition">
|
||||||
this.render_condition(condition!, i)
|
${ensureArray(this.trace.config.condition)?.map((condition, i) =>
|
||||||
|
this.render_condition(condition!, i)
|
||||||
|
)}
|
||||||
|
</hat-graph>
|
||||||
|
${ensureArray(this.trace.config.action).map((action, i) =>
|
||||||
|
this.render_node(action, `action/${i}`)
|
||||||
)}
|
)}
|
||||||
</hat-graph>
|
</hat-graph>
|
||||||
${ensureArray(this.trace.config.action).map((action, i) =>
|
<div class="actions">
|
||||||
this.render_node(action, `action/${i}`)
|
<mwc-icon-button
|
||||||
)}
|
.disabled=${paths.length === 0 || paths[0] === this.selected}
|
||||||
</hat-graph>
|
@click=${this.previousTrackedNode}
|
||||||
<div class="actions">
|
>
|
||||||
<mwc-icon-button
|
<ha-svg-icon .path=${mdiChevronUp}></ha-svg-icon>
|
||||||
.disabled=${paths.length === 0 || paths[0] === this.selected}
|
</mwc-icon-button>
|
||||||
@click=${this.previousTrackedNode}
|
<mwc-icon-button
|
||||||
>
|
.disabled=${paths.length === 0 ||
|
||||||
<ha-svg-icon .path=${mdiChevronUp}></ha-svg-icon>
|
paths[paths.length - 1] === this.selected}
|
||||||
</mwc-icon-button>
|
@click=${this.nextTrackedNode}
|
||||||
<mwc-icon-button
|
>
|
||||||
.disabled=${paths.length === 0 ||
|
<ha-svg-icon .path=${mdiChevronDown}></ha-svg-icon>
|
||||||
paths[paths.length - 1] === this.selected}
|
</mwc-icon-button>
|
||||||
@click=${this.nextTrackedNode}
|
</div>
|
||||||
>
|
`;
|
||||||
<ha-svg-icon .path=${mdiChevronDown}></ha-svg-icon>
|
} catch (err) {
|
||||||
</mwc-icon-button>
|
return html`
|
||||||
</div>
|
<div class="error">
|
||||||
`;
|
Error rendering graph. Please download trace and share with the
|
||||||
|
developers.
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected update(changedProps: PropertyValues<this>) {
|
protected update(changedProps: PropertyValues<this>) {
|
||||||
@ -539,6 +548,10 @@ class HatScriptGraph extends LitElement {
|
|||||||
.parent {
|
.parent {
|
||||||
margin-left: 8px;
|
margin-left: 8px;
|
||||||
}
|
}
|
||||||
|
.error {
|
||||||
|
padding: 16px;
|
||||||
|
max-width: 300px;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,9 @@ export interface ManualAutomationConfig {
|
|||||||
id?: string;
|
id?: string;
|
||||||
alias?: string;
|
alias?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
trigger: Trigger[];
|
trigger: Trigger | Trigger[];
|
||||||
condition?: Condition[];
|
condition?: Condition | Condition[];
|
||||||
action: Action[];
|
action: Action | Action[];
|
||||||
mode?: typeof MODES[number];
|
mode?: typeof MODES[number];
|
||||||
max?: number;
|
max?: number;
|
||||||
max_exceeded?:
|
max_exceeded?:
|
||||||
@ -161,7 +161,7 @@ export type Trigger =
|
|||||||
export interface LogicalCondition {
|
export interface LogicalCondition {
|
||||||
condition: "and" | "not" | "or";
|
condition: "and" | "not" | "or";
|
||||||
alias?: string;
|
alias?: string;
|
||||||
conditions: Condition[];
|
conditions: Condition | Condition[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StateCondition {
|
export interface StateCondition {
|
||||||
|
@ -22,7 +22,7 @@ export interface ScriptEntity extends HassEntityBase {
|
|||||||
|
|
||||||
export interface ScriptConfig {
|
export interface ScriptConfig {
|
||||||
alias: string;
|
alias: string;
|
||||||
sequence: Action[];
|
sequence: Action | Action[];
|
||||||
icon?: string;
|
icon?: string;
|
||||||
mode?: typeof MODES[number];
|
mode?: typeof MODES[number];
|
||||||
max?: number;
|
max?: number;
|
||||||
@ -89,7 +89,7 @@ export interface RepeatAction {
|
|||||||
|
|
||||||
interface BaseRepeat {
|
interface BaseRepeat {
|
||||||
alias?: string;
|
alias?: string;
|
||||||
sequence: Action[];
|
sequence: Action | Action[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CountRepeat extends BaseRepeat {
|
export interface CountRepeat extends BaseRepeat {
|
||||||
@ -107,13 +107,13 @@ export interface UntilRepeat extends BaseRepeat {
|
|||||||
export interface ChooseActionChoice {
|
export interface ChooseActionChoice {
|
||||||
alias?: string;
|
alias?: string;
|
||||||
conditions: string | Condition[];
|
conditions: string | Condition[];
|
||||||
sequence: Action[];
|
sequence: Action | Action[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChooseAction {
|
export interface ChooseAction {
|
||||||
alias?: string;
|
alias?: string;
|
||||||
choose: ChooseActionChoice[];
|
choose: ChooseActionChoice[];
|
||||||
default?: Action[];
|
default?: Action | Action[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VariablesAction {
|
export interface VariablesAction {
|
||||||
|
@ -105,6 +105,7 @@ export class HaAutomationTracePathDetails extends LitElement {
|
|||||||
path,
|
path,
|
||||||
timestamp,
|
timestamp,
|
||||||
result,
|
result,
|
||||||
|
error,
|
||||||
changed_variables,
|
changed_variables,
|
||||||
...rest
|
...rest
|
||||||
} = trace as any;
|
} = trace as any;
|
||||||
@ -116,6 +117,8 @@ export class HaAutomationTracePathDetails extends LitElement {
|
|||||||
${result
|
${result
|
||||||
? html`Result:
|
? html`Result:
|
||||||
<pre>${safeDump(result)}</pre>`
|
<pre>${safeDump(result)}</pre>`
|
||||||
|
: error
|
||||||
|
? html`<div class="error">Error: ${error}</div>`
|
||||||
: ""}
|
: ""}
|
||||||
${Object.keys(rest).length === 0
|
${Object.keys(rest).length === 0
|
||||||
? ""
|
? ""
|
||||||
@ -232,6 +235,10 @@ ${safeDump(trace.changed_variables).trimRight()}</pre
|
|||||||
pre {
|
pre {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: var(--error-color);
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -469,6 +469,11 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
|
|
||||||
.graph {
|
.graph {
|
||||||
border-right: 1px solid var(--divider-color);
|
border-right: 1px solid var(--divider-color);
|
||||||
|
overflow-x: auto;
|
||||||
|
max-width: 50%;
|
||||||
|
}
|
||||||
|
:host([narrow]) .graph {
|
||||||
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.info {
|
.info {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user