mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Add compatibility with latest trace API (#8700)
This commit is contained in:
parent
5156c67226
commit
9676d2cee7
@ -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",
|
||||
@ -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": [
|
||||
{
|
||||
|
@ -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",
|
||||
@ -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": [
|
||||
{
|
||||
|
@ -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 {
|
||||
|
@ -12,7 +12,7 @@ import {
|
||||
AutomationTraceExtended,
|
||||
ChooseActionTrace,
|
||||
getDataFromPath,
|
||||
} from "../../data/automation_debug";
|
||||
} from "../../data/trace";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import "./ha-timeline";
|
||||
import {
|
||||
@ -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("/");
|
||||
|
||||
@ -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;
|
||||
|
@ -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;
|
||||
@ -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 = (
|
@ -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";
|
||||
@ -31,7 +28,7 @@ export class MoreInfoLogbook extends LitElement {
|
||||
|
||||
@internalProperty() private _logbookEntries?: LogbookEntry[];
|
||||
|
||||
@internalProperty() private _traceContexts?: AutomationTraceContexts;
|
||||
@internalProperty() private _traceContexts?: TraceContexts;
|
||||
|
||||
@internalProperty() private _persons = {};
|
||||
|
||||
@ -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]
|
||||
|
@ -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";
|
||||
@ -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();
|
||||
|
||||
@ -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!
|
||||
);
|
||||
|
@ -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";
|
||||
@ -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[] = [];
|
||||
|
||||
@ -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
|
||||
}`}
|
||||
|
@ -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,
|
||||
@ -54,7 +54,7 @@ export class HaPanelLogbook extends LitElement {
|
||||
|
||||
@internalProperty() private _userIdToName = {};
|
||||
|
||||
@internalProperty() private _traceContexts: AutomationTraceContexts = {};
|
||||
@internalProperty() private _traceContexts: TraceContexts = {};
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
@ -267,7 +267,7 @@ export class HaPanelLogbook extends LitElement {
|
||||
this._endDate.toISOString(),
|
||||
this._entityId
|
||||
),
|
||||
loadAutomationTraceContexts(this.hass),
|
||||
loadTraceContexts(this.hass),
|
||||
this._fetchUserDone,
|
||||
]);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user