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
4 changes: 2 additions & 2 deletions gallery/src/data/traces/basic_trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { DemoTrace } from "./types";

export const basicTrace: DemoTrace = {
trace: {
automation_id: "1615419646544",
last_action: "action/0/choose/0/sequence/0",
last_condition: "condition/0",
run_id: "0",
Expand All @@ -12,7 +11,8 @@ export const basicTrace: DemoTrace = {
finish: "2021-03-22T19:17:09.556129+00:00",
},
trigger: "state of input_boolean.toggle_1",
unique_id: "1615419646544",
domain: "automation",
item_id: "1615419646544",
action_trace: {
"action/0": [
{
Expand Down
4 changes: 2 additions & 2 deletions gallery/src/data/traces/motion-light-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { DemoTrace } from "./types";

export const motionLightTrace: DemoTrace = {
trace: {
automation_id: "",
last_action: "action/3",
last_condition: null,
run_id: "1",
Expand All @@ -12,7 +11,8 @@ export const motionLightTrace: DemoTrace = {
finish: "2021-03-14T06:07:53.287525+00:00",
},
trigger: "state of binary_sensor.pauluss_macbook_pro_camera_in_use",
unique_id: "1614732497392",
domain: "automation",
item_id: "1614732497392",
action_trace: {
"action/0": [
{
Expand Down
2 changes: 1 addition & 1 deletion gallery/src/data/traces/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AutomationTraceExtended } from "../../../../src/data/automation_debug";
import { AutomationTraceExtended } from "../../../../src/data/trace";
import { LogbookEntry } from "../../../../src/data/logbook";

export interface DemoTrace {
Expand Down
6 changes: 3 additions & 3 deletions src/components/trace/hat-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
AutomationTraceExtended,
ChooseActionTrace,
getDataFromPath,
} from "../../data/automation_debug";
} from "../../data/trace";
import { HomeAssistant } from "../../types";
import "./ha-timeline";
import {
Expand Down Expand Up @@ -288,7 +288,7 @@ class ActionRenderer {
}

// Render choice
for (; i < this.keys.length; i++) {
while (i < this.keys.length) {
const path = this.keys[i];
const parts = path.split("/");

Expand All @@ -299,7 +299,7 @@ class ActionRenderer {

// We know it's an action sequence, so force the type like that
// for rendering.
this._renderItem(i, getActionType(this._getDataFromPath(path)));
i = this._renderItem(i, getActionType(this._getDataFromPath(path)));
}

return i;
Expand Down
51 changes: 32 additions & 19 deletions src/data/automation_debug.ts → src/data/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export type ActionTrace =
| ChooseChoiceActionTrace;

export interface AutomationTrace {
automation_id: string;
unique_id: string;
domain: string;
item_id: string;
last_action: string | null;
last_condition: string | null;
run_id: string;
Expand All @@ -62,38 +62,51 @@ export interface AutomationTraceExtended extends AutomationTrace {
config: AutomationConfig;
}

export const loadAutomationTrace = (
interface TraceTypes {
automation: {
short: AutomationTrace;
extended: AutomationTraceExtended;
};
}

export const loadTrace = <T extends keyof TraceTypes>(
hass: HomeAssistant,
automation_id: string,
domain: T,
item_id: string,
run_id: string
): Promise<AutomationTraceExtended> =>
): Promise<TraceTypes[T]["extended"]> =>
hass.callWS({
type: "automation/trace/get",
automation_id,
type: "trace/get",
domain,
item_id,
run_id,
});

export const loadAutomationTraces = (
export const loadTraces = <T extends keyof TraceTypes>(
hass: HomeAssistant,
automation_id?: string
): Promise<AutomationTrace[]> =>
domain: T,
item_id: string
): Promise<Array<TraceTypes[T]["short"]>> =>
hass.callWS({
type: "automation/trace/list",
automation_id,
type: "trace/list",
domain,
item_id,
});

export type AutomationTraceContexts = Record<
export type TraceContexts = Record<
string,
{ run_id: string; automation_id: string }
{ run_id: string; domain: string; item_id: string }
>;

export const loadAutomationTraceContexts = (
export const loadTraceContexts = (
hass: HomeAssistant,
automation_id?: string
): Promise<AutomationTraceContexts> =>
domain?: string,
item_id?: string
): Promise<TraceContexts> =>
hass.callWS({
type: "automation/trace/contexts",
automation_id,
type: "trace/contexts",
domain,
item_id,
});

export const getDataFromPath = (
Expand Down
9 changes: 3 additions & 6 deletions src/dialogs/more-info/ha-more-info-logbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import { computeStateDomain } from "../../common/entity/compute_state_domain";
import { throttle } from "../../common/util/throttle";
import "../../components/ha-circular-progress";
import "../../components/state-history-charts";
import {
AutomationTraceContexts,
loadAutomationTraceContexts,
} from "../../data/automation_debug";
import { TraceContexts, loadTraceContexts } from "../../data/trace";
import { getLogbookData, LogbookEntry } from "../../data/logbook";
import "../../panels/logbook/ha-logbook";
import { haStyle, haStyleScrollbar } from "../../resources/styles";
Expand All @@ -31,7 +28,7 @@ export class MoreInfoLogbook extends LitElement {

@internalProperty() private _logbookEntries?: LogbookEntry[];

@internalProperty() private _traceContexts?: AutomationTraceContexts;
@internalProperty() private _traceContexts?: TraceContexts;

@internalProperty() private _persons = {};

Expand Down Expand Up @@ -136,7 +133,7 @@ export class MoreInfoLogbook extends LitElement {
this.entityId,
true
),
loadAutomationTraceContexts(this.hass),
loadTraceContexts(this.hass),
]);
this._logbookEntries = this._logbookEntries
? [...newEntries, ...this._logbookEntries]
Expand Down
11 changes: 6 additions & 5 deletions src/panels/config/automation/trace/ha-automation-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { AutomationEntity } from "../../../../data/automation";
import {
AutomationTrace,
AutomationTraceExtended,
loadAutomationTrace,
loadAutomationTraces,
} from "../../../../data/automation_debug";
loadTrace,
loadTraces,
} from "../../../../data/trace";
import "../../../../components/ha-card";
import "../../../../components/trace/hat-trace";
import { haStyle } from "../../../../resources/styles";
Expand Down Expand Up @@ -165,7 +165,7 @@ export class HaAutomationTrace extends LitElement {
}

private async _loadTraces(runId?: string) {
this._traces = await loadAutomationTraces(this.hass, this.automationId);
this._traces = await loadTraces(this.hass, "automation", this.automationId);
// Newest will be on top.
this._traces.reverse();

Expand Down Expand Up @@ -203,8 +203,9 @@ export class HaAutomationTrace extends LitElement {
}

private async _loadTrace() {
const trace = await loadAutomationTrace(
const trace = await loadTrace(
this.hass,
"automation",
this.automationId,
this._runId!
);
Expand Down
6 changes: 3 additions & 3 deletions src/panels/logbook/ha-logbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { computeRTL, emitRTLDirection } from "../../common/util/compute_rtl";
import "../../components/entity/state-badge";
import "../../components/ha-circular-progress";
import "../../components/ha-relative-time";
import { AutomationTraceContexts } from "../../data/automation_debug";
import { TraceContexts } from "../../data/trace";
import { LogbookEntry } from "../../data/logbook";
import { haStyle, haStyleScrollbar } from "../../resources/styles";
import { HomeAssistant } from "../../types";
Expand All @@ -34,7 +34,7 @@ class HaLogbook extends LitElement {
@property({ attribute: false }) public userIdToName = {};

@property({ attribute: false })
public traceContexts: AutomationTraceContexts = {};
public traceContexts: TraceContexts = {};

@property({ attribute: false }) public entries: LogbookEntry[] = [];

Expand Down Expand Up @@ -218,7 +218,7 @@ class HaLogbook extends LitElement {
-
<a
href=${`/config/automation/trace/${
this.traceContexts[item.context_id!].automation_id
this.traceContexts[item.context_id!].item_id
}?run_id=${
this.traceContexts[item.context_id!].run_id
}`}
Expand Down
6 changes: 3 additions & 3 deletions src/panels/logbook/ha-panel-logbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import "../../components/ha-date-range-picker";
import type { DateRangePickerRanges } from "../../components/ha-date-range-picker";
import "../../components/ha-icon-button";
import "../../components/ha-menu-button";
import { AutomationTraceContexts, loadAutomationTraceContexts } from "../../data/automation_debug";
import { TraceContexts, loadTraceContexts } from "../../data/trace";
import {
clearLogbookCache,
getLogbookData,
Expand Down Expand Up @@ -54,7 +54,7 @@ export class HaPanelLogbook extends LitElement {

@internalProperty() private _userIdToName = {};

@internalProperty() private _traceContexts: AutomationTraceContexts = {};
@internalProperty() private _traceContexts: TraceContexts = {};

public constructor() {
super();
Expand Down Expand Up @@ -267,7 +267,7 @@ export class HaPanelLogbook extends LitElement {
this._endDate.toISOString(),
this._entityId
),
loadAutomationTraceContexts(this.hass),
loadTraceContexts(this.hass),
this._fetchUserDone,
]);

Expand Down