mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +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 = {
|
export const basicTrace: DemoTrace = {
|
||||||
trace: {
|
trace: {
|
||||||
automation_id: "1615419646544",
|
|
||||||
last_action: "action/0/choose/0/sequence/0",
|
last_action: "action/0/choose/0/sequence/0",
|
||||||
last_condition: "condition/0",
|
last_condition: "condition/0",
|
||||||
run_id: "0",
|
run_id: "0",
|
||||||
@ -12,7 +11,8 @@ export const basicTrace: DemoTrace = {
|
|||||||
finish: "2021-03-22T19:17:09.556129+00:00",
|
finish: "2021-03-22T19:17:09.556129+00:00",
|
||||||
},
|
},
|
||||||
trigger: "state of input_boolean.toggle_1",
|
trigger: "state of input_boolean.toggle_1",
|
||||||
unique_id: "1615419646544",
|
domain: "automation",
|
||||||
|
item_id: "1615419646544",
|
||||||
action_trace: {
|
action_trace: {
|
||||||
"action/0": [
|
"action/0": [
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@ import { DemoTrace } from "./types";
|
|||||||
|
|
||||||
export const motionLightTrace: DemoTrace = {
|
export const motionLightTrace: DemoTrace = {
|
||||||
trace: {
|
trace: {
|
||||||
automation_id: "",
|
|
||||||
last_action: "action/3",
|
last_action: "action/3",
|
||||||
last_condition: null,
|
last_condition: null,
|
||||||
run_id: "1",
|
run_id: "1",
|
||||||
@ -12,7 +11,8 @@ export const motionLightTrace: DemoTrace = {
|
|||||||
finish: "2021-03-14T06:07:53.287525+00:00",
|
finish: "2021-03-14T06:07:53.287525+00:00",
|
||||||
},
|
},
|
||||||
trigger: "state of binary_sensor.pauluss_macbook_pro_camera_in_use",
|
trigger: "state of binary_sensor.pauluss_macbook_pro_camera_in_use",
|
||||||
unique_id: "1614732497392",
|
domain: "automation",
|
||||||
|
item_id: "1614732497392",
|
||||||
action_trace: {
|
action_trace: {
|
||||||
"action/0": [
|
"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";
|
import { LogbookEntry } from "../../../../src/data/logbook";
|
||||||
|
|
||||||
export interface DemoTrace {
|
export interface DemoTrace {
|
||||||
|
@ -12,7 +12,7 @@ import {
|
|||||||
AutomationTraceExtended,
|
AutomationTraceExtended,
|
||||||
ChooseActionTrace,
|
ChooseActionTrace,
|
||||||
getDataFromPath,
|
getDataFromPath,
|
||||||
} from "../../data/automation_debug";
|
} from "../../data/trace";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import "./ha-timeline";
|
import "./ha-timeline";
|
||||||
import {
|
import {
|
||||||
@ -288,7 +288,7 @@ class ActionRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render choice
|
// Render choice
|
||||||
for (; i < this.keys.length; i++) {
|
while (i < this.keys.length) {
|
||||||
const path = this.keys[i];
|
const path = this.keys[i];
|
||||||
const parts = path.split("/");
|
const parts = path.split("/");
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ class ActionRenderer {
|
|||||||
|
|
||||||
// We know it's an action sequence, so force the type like that
|
// We know it's an action sequence, so force the type like that
|
||||||
// for rendering.
|
// for rendering.
|
||||||
this._renderItem(i, getActionType(this._getDataFromPath(path)));
|
i = this._renderItem(i, getActionType(this._getDataFromPath(path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
@ -41,8 +41,8 @@ export type ActionTrace =
|
|||||||
| ChooseChoiceActionTrace;
|
| ChooseChoiceActionTrace;
|
||||||
|
|
||||||
export interface AutomationTrace {
|
export interface AutomationTrace {
|
||||||
automation_id: string;
|
domain: string;
|
||||||
unique_id: string;
|
item_id: string;
|
||||||
last_action: string | null;
|
last_action: string | null;
|
||||||
last_condition: string | null;
|
last_condition: string | null;
|
||||||
run_id: string;
|
run_id: string;
|
||||||
@ -62,38 +62,51 @@ export interface AutomationTraceExtended extends AutomationTrace {
|
|||||||
config: AutomationConfig;
|
config: AutomationConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadAutomationTrace = (
|
interface TraceTypes {
|
||||||
|
automation: {
|
||||||
|
short: AutomationTrace;
|
||||||
|
extended: AutomationTraceExtended;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const loadTrace = <T extends keyof TraceTypes>(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
automation_id: string,
|
domain: T,
|
||||||
|
item_id: string,
|
||||||
run_id: string
|
run_id: string
|
||||||
): Promise<AutomationTraceExtended> =>
|
): Promise<TraceTypes[T]["extended"]> =>
|
||||||
hass.callWS({
|
hass.callWS({
|
||||||
type: "automation/trace/get",
|
type: "trace/get",
|
||||||
automation_id,
|
domain,
|
||||||
|
item_id,
|
||||||
run_id,
|
run_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const loadAutomationTraces = (
|
export const loadTraces = <T extends keyof TraceTypes>(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
automation_id?: string
|
domain: T,
|
||||||
): Promise<AutomationTrace[]> =>
|
item_id: string
|
||||||
|
): Promise<Array<TraceTypes[T]["short"]>> =>
|
||||||
hass.callWS({
|
hass.callWS({
|
||||||
type: "automation/trace/list",
|
type: "trace/list",
|
||||||
automation_id,
|
domain,
|
||||||
|
item_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
export type AutomationTraceContexts = Record<
|
export type TraceContexts = Record<
|
||||||
string,
|
string,
|
||||||
{ run_id: string; automation_id: string }
|
{ run_id: string; domain: string; item_id: string }
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export const loadAutomationTraceContexts = (
|
export const loadTraceContexts = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
automation_id?: string
|
domain?: string,
|
||||||
): Promise<AutomationTraceContexts> =>
|
item_id?: string
|
||||||
|
): Promise<TraceContexts> =>
|
||||||
hass.callWS({
|
hass.callWS({
|
||||||
type: "automation/trace/contexts",
|
type: "trace/contexts",
|
||||||
automation_id,
|
domain,
|
||||||
|
item_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const getDataFromPath = (
|
export const getDataFromPath = (
|
@ -14,10 +14,7 @@ import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
|||||||
import { throttle } from "../../common/util/throttle";
|
import { throttle } from "../../common/util/throttle";
|
||||||
import "../../components/ha-circular-progress";
|
import "../../components/ha-circular-progress";
|
||||||
import "../../components/state-history-charts";
|
import "../../components/state-history-charts";
|
||||||
import {
|
import { TraceContexts, loadTraceContexts } from "../../data/trace";
|
||||||
AutomationTraceContexts,
|
|
||||||
loadAutomationTraceContexts,
|
|
||||||
} from "../../data/automation_debug";
|
|
||||||
import { getLogbookData, LogbookEntry } from "../../data/logbook";
|
import { getLogbookData, LogbookEntry } from "../../data/logbook";
|
||||||
import "../../panels/logbook/ha-logbook";
|
import "../../panels/logbook/ha-logbook";
|
||||||
import { haStyle, haStyleScrollbar } from "../../resources/styles";
|
import { haStyle, haStyleScrollbar } from "../../resources/styles";
|
||||||
@ -31,7 +28,7 @@ export class MoreInfoLogbook extends LitElement {
|
|||||||
|
|
||||||
@internalProperty() private _logbookEntries?: LogbookEntry[];
|
@internalProperty() private _logbookEntries?: LogbookEntry[];
|
||||||
|
|
||||||
@internalProperty() private _traceContexts?: AutomationTraceContexts;
|
@internalProperty() private _traceContexts?: TraceContexts;
|
||||||
|
|
||||||
@internalProperty() private _persons = {};
|
@internalProperty() private _persons = {};
|
||||||
|
|
||||||
@ -136,7 +133,7 @@ export class MoreInfoLogbook extends LitElement {
|
|||||||
this.entityId,
|
this.entityId,
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
loadAutomationTraceContexts(this.hass),
|
loadTraceContexts(this.hass),
|
||||||
]);
|
]);
|
||||||
this._logbookEntries = this._logbookEntries
|
this._logbookEntries = this._logbookEntries
|
||||||
? [...newEntries, ...this._logbookEntries]
|
? [...newEntries, ...this._logbookEntries]
|
||||||
|
@ -12,9 +12,9 @@ import { AutomationEntity } from "../../../../data/automation";
|
|||||||
import {
|
import {
|
||||||
AutomationTrace,
|
AutomationTrace,
|
||||||
AutomationTraceExtended,
|
AutomationTraceExtended,
|
||||||
loadAutomationTrace,
|
loadTrace,
|
||||||
loadAutomationTraces,
|
loadTraces,
|
||||||
} from "../../../../data/automation_debug";
|
} from "../../../../data/trace";
|
||||||
import "../../../../components/ha-card";
|
import "../../../../components/ha-card";
|
||||||
import "../../../../components/trace/hat-trace";
|
import "../../../../components/trace/hat-trace";
|
||||||
import { haStyle } from "../../../../resources/styles";
|
import { haStyle } from "../../../../resources/styles";
|
||||||
@ -165,7 +165,7 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _loadTraces(runId?: string) {
|
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.
|
// Newest will be on top.
|
||||||
this._traces.reverse();
|
this._traces.reverse();
|
||||||
|
|
||||||
@ -203,8 +203,9 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _loadTrace() {
|
private async _loadTrace() {
|
||||||
const trace = await loadAutomationTrace(
|
const trace = await loadTrace(
|
||||||
this.hass,
|
this.hass,
|
||||||
|
"automation",
|
||||||
this.automationId,
|
this.automationId,
|
||||||
this._runId!
|
this._runId!
|
||||||
);
|
);
|
||||||
|
@ -22,7 +22,7 @@ import { computeRTL, emitRTLDirection } from "../../common/util/compute_rtl";
|
|||||||
import "../../components/entity/state-badge";
|
import "../../components/entity/state-badge";
|
||||||
import "../../components/ha-circular-progress";
|
import "../../components/ha-circular-progress";
|
||||||
import "../../components/ha-relative-time";
|
import "../../components/ha-relative-time";
|
||||||
import { AutomationTraceContexts } from "../../data/automation_debug";
|
import { TraceContexts } from "../../data/trace";
|
||||||
import { LogbookEntry } from "../../data/logbook";
|
import { LogbookEntry } from "../../data/logbook";
|
||||||
import { haStyle, haStyleScrollbar } from "../../resources/styles";
|
import { haStyle, haStyleScrollbar } from "../../resources/styles";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
@ -34,7 +34,7 @@ class HaLogbook extends LitElement {
|
|||||||
@property({ attribute: false }) public userIdToName = {};
|
@property({ attribute: false }) public userIdToName = {};
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public traceContexts: AutomationTraceContexts = {};
|
public traceContexts: TraceContexts = {};
|
||||||
|
|
||||||
@property({ attribute: false }) public entries: LogbookEntry[] = [];
|
@property({ attribute: false }) public entries: LogbookEntry[] = [];
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ class HaLogbook extends LitElement {
|
|||||||
-
|
-
|
||||||
<a
|
<a
|
||||||
href=${`/config/automation/trace/${
|
href=${`/config/automation/trace/${
|
||||||
this.traceContexts[item.context_id!].automation_id
|
this.traceContexts[item.context_id!].item_id
|
||||||
}?run_id=${
|
}?run_id=${
|
||||||
this.traceContexts[item.context_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 type { DateRangePickerRanges } from "../../components/ha-date-range-picker";
|
||||||
import "../../components/ha-icon-button";
|
import "../../components/ha-icon-button";
|
||||||
import "../../components/ha-menu-button";
|
import "../../components/ha-menu-button";
|
||||||
import { AutomationTraceContexts, loadAutomationTraceContexts } from "../../data/automation_debug";
|
import { TraceContexts, loadTraceContexts } from "../../data/trace";
|
||||||
import {
|
import {
|
||||||
clearLogbookCache,
|
clearLogbookCache,
|
||||||
getLogbookData,
|
getLogbookData,
|
||||||
@ -54,7 +54,7 @@ export class HaPanelLogbook extends LitElement {
|
|||||||
|
|
||||||
@internalProperty() private _userIdToName = {};
|
@internalProperty() private _userIdToName = {};
|
||||||
|
|
||||||
@internalProperty() private _traceContexts: AutomationTraceContexts = {};
|
@internalProperty() private _traceContexts: TraceContexts = {};
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
super();
|
super();
|
||||||
@ -267,7 +267,7 @@ export class HaPanelLogbook extends LitElement {
|
|||||||
this._endDate.toISOString(),
|
this._endDate.toISOString(),
|
||||||
this._entityId
|
this._entityId
|
||||||
),
|
),
|
||||||
loadAutomationTraceContexts(this.hass),
|
loadTraceContexts(this.hass),
|
||||||
this._fetchUserDone,
|
this._fetchUserDone,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user