Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/trace/hat-script-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class HatScriptGraph extends LitElement {
const trace = this.trace.trace[path] as ChooseActionTraceStep[] | undefined;
const trace_path = trace?.[0].result
? trace[0].result.choice === "default"
? [config.choose.length]
? [config.choose?.length || 0]
Comment thread
balloob marked this conversation as resolved.
: [trace[0].result.choice]
: [];
return html`
Expand All @@ -167,7 +167,7 @@ class HatScriptGraph extends LitElement {
nofocus
></hat-graph-node>

${config.choose.map((branch, i) => {
${config.choose?.map((branch, i) => {
const branch_path = `${path}/choose/${i}`;
const track_this =
trace !== undefined && trace[0].result?.choice === i;
Expand Down Expand Up @@ -466,6 +466,10 @@ class HatScriptGraph extends LitElement {
</div>
`;
} catch (err) {
if (__DEV__) {
// eslint-disable-next-line no-console
console.log("Error creating script graph:", err);
}
return html`
<div class="error">
Error rendering graph. Please download trace and share with the
Expand Down
2 changes: 1 addition & 1 deletion src/data/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export interface ChooseActionChoice {

export interface ChooseAction {
alias?: string;
choose: ChooseActionChoice[];
choose: ChooseActionChoice[] | null;
default?: Action | Action[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
const action = this.action;

return html`
${action.choose.map(
${(action.choose || []).map(
(option, idx) => html`<ha-card>
<mwc-icon-button
.idx=${idx}
Expand Down Expand Up @@ -101,7 +101,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
ev.stopPropagation();
const value = ev.detail.value as Condition[];
const index = (ev.target as any).idx;
const choose = [...this.action.choose];
const choose = this.action.choose ? [...this.action.choose] : [];
choose[index].conditions = value;
fireEvent(this, "value-changed", {
value: { ...this.action, choose },
Expand All @@ -112,15 +112,15 @@ export class HaChooseAction extends LitElement implements ActionElement {
ev.stopPropagation();
const value = ev.detail.value as Action[];
const index = (ev.target as any).idx;
const choose = [...this.action.choose];
const choose = this.action.choose ? [...this.action.choose] : [];
choose[index].sequence = value;
fireEvent(this, "value-changed", {
value: { ...this.action, choose },
});
}

private _addOption() {
const choose = [...this.action.choose];
const choose = this.action.choose ? [...this.action.choose] : [];
choose.push({ conditions: [], sequence: [] });
fireEvent(this, "value-changed", {
value: { ...this.action, choose },
Expand All @@ -129,7 +129,7 @@ export class HaChooseAction extends LitElement implements ActionElement {

private _removeOption(ev: CustomEvent) {
const index = (ev.currentTarget as any).idx;
const choose = [...this.action.choose];
const choose = this.action.choose ? [...this.action.choose] : [];
choose.splice(index, 1);
fireEvent(this, "value-changed", {
value: { ...this.action, choose },
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/automation/trace/ha-automation-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class HaAutomationTrace extends LitElement {
<ha-svg-icon .path=${mdiRefresh}></ha-svg-icon>
</mwc-icon-button>
<mwc-icon-button
.disabled=${!this._runId}
.disabled=${!this._trace}
label="Download Trace"
@click=${this._downloadTrace}
>
Expand Down