mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Add repeat to trace timeline (#12547)
This commit is contained in:
parent
3b6b4d7664
commit
e51e3e79d5
@ -25,9 +25,11 @@ import {
|
|||||||
ChooseAction,
|
ChooseAction,
|
||||||
ChooseActionChoice,
|
ChooseActionChoice,
|
||||||
getActionType,
|
getActionType,
|
||||||
|
RepeatAction,
|
||||||
} from "../../data/script";
|
} from "../../data/script";
|
||||||
import { describeAction } from "../../data/script_i18n";
|
import { describeAction } from "../../data/script_i18n";
|
||||||
import {
|
import {
|
||||||
|
ActionTraceStep,
|
||||||
AutomationTraceExtended,
|
AutomationTraceExtended,
|
||||||
ChooseActionTraceStep,
|
ChooseActionTraceStep,
|
||||||
getDataFromPath,
|
getDataFromPath,
|
||||||
@ -105,7 +107,7 @@ class LogbookRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get hasNext() {
|
get hasNext() {
|
||||||
return this.curIndex !== this.logbookEntries.length;
|
return this.curIndex < this.logbookEntries.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeRenderItem() {
|
maybeRenderItem() {
|
||||||
@ -201,7 +203,7 @@ class ActionRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get hasNext() {
|
get hasNext() {
|
||||||
return this.curIndex !== this.keys.length;
|
return this.curIndex < this.keys.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderItem() {
|
renderItem() {
|
||||||
@ -214,15 +216,31 @@ class ActionRenderer {
|
|||||||
|
|
||||||
private _renderItem(
|
private _renderItem(
|
||||||
index: number,
|
index: number,
|
||||||
actionType?: ReturnType<typeof getActionType>
|
actionType?: ReturnType<typeof getActionType>,
|
||||||
|
renderAllIterations?: boolean
|
||||||
): number {
|
): number {
|
||||||
const value = this._getItem(index);
|
const value = this._getItem(index);
|
||||||
|
|
||||||
if (isTriggerPath(value[0].path)) {
|
if (renderAllIterations) {
|
||||||
return this._handleTrigger(index, value[0] as TriggerTraceStep);
|
let i;
|
||||||
|
value.forEach((item) => {
|
||||||
|
i = this._renderIteration(index, item, actionType);
|
||||||
|
});
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return this._renderIteration(index, value[0], actionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _renderIteration(
|
||||||
|
index: number,
|
||||||
|
value: ActionTraceStep,
|
||||||
|
actionType?: ReturnType<typeof getActionType>
|
||||||
|
) {
|
||||||
|
if (isTriggerPath(value.path)) {
|
||||||
|
return this._handleTrigger(index, value as TriggerTraceStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
const timestamp = new Date(value[0].timestamp);
|
const timestamp = new Date(value.timestamp);
|
||||||
|
|
||||||
// Render all logbook items that are in front of this item.
|
// Render all logbook items that are in front of this item.
|
||||||
while (
|
while (
|
||||||
@ -235,7 +253,7 @@ class ActionRenderer {
|
|||||||
this.logbookRenderer.flush();
|
this.logbookRenderer.flush();
|
||||||
this.timeTracker.maybeRenderTime(timestamp);
|
this.timeTracker.maybeRenderTime(timestamp);
|
||||||
|
|
||||||
const path = value[0].path;
|
const path = value.path;
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
data = getDataFromPath(this.trace.config, path);
|
data = getDataFromPath(this.trace.config, path);
|
||||||
@ -263,6 +281,10 @@ class ActionRenderer {
|
|||||||
return this._handleChoose(index);
|
return this._handleChoose(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (actionType === "repeat") {
|
||||||
|
return this._handleRepeat(index);
|
||||||
|
}
|
||||||
|
|
||||||
this._renderEntry(path, describeAction(this.hass, data, actionType));
|
this._renderEntry(path, describeAction(this.hass, data, actionType));
|
||||||
|
|
||||||
let i = index + 1;
|
let i = index + 1;
|
||||||
@ -374,6 +396,34 @@ class ActionRenderer {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _handleRepeat(index: number): number {
|
||||||
|
const repeatPath = this.keys[index];
|
||||||
|
const startLevel = repeatPath.split("/").length;
|
||||||
|
|
||||||
|
const repeatConfig = this._getDataFromPath(
|
||||||
|
this.keys[index]
|
||||||
|
) as RepeatAction;
|
||||||
|
const name = repeatConfig.alias || describeAction(this.hass, repeatConfig);
|
||||||
|
|
||||||
|
this._renderEntry(repeatPath, name);
|
||||||
|
|
||||||
|
let i;
|
||||||
|
|
||||||
|
for (i = index + 1; i < this.keys.length; i++) {
|
||||||
|
const path = this.keys[i];
|
||||||
|
const parts = path.split("/");
|
||||||
|
|
||||||
|
// We're done if no more sequence in current level
|
||||||
|
if (parts.length <= startLevel) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = this._renderItem(i, getActionType(this._getDataFromPath(path)), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
private _renderEntry(
|
private _renderEntry(
|
||||||
path: string,
|
path: string,
|
||||||
description: string,
|
description: string,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user