mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-13 12:26:35 +00:00
Add blueprint config to trace (#8751)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
8e3a7576ea
commit
c11bbcf442
@ -238,6 +238,9 @@ export const deleteAutomation = (hass: HomeAssistant, id: string) =>
|
|||||||
|
|
||||||
let inititialAutomationEditorData: Partial<AutomationConfig> | undefined;
|
let inititialAutomationEditorData: Partial<AutomationConfig> | undefined;
|
||||||
|
|
||||||
|
export const getAutomationConfig = (hass: HomeAssistant, id: string) =>
|
||||||
|
hass.callApi<AutomationConfig>("GET", `config/automation/config/${id}`);
|
||||||
|
|
||||||
export const showAutomationEditor = (
|
export const showAutomationEditor = (
|
||||||
el: HTMLElement,
|
el: HTMLElement,
|
||||||
data?: Partial<AutomationConfig>
|
data?: Partial<AutomationConfig>
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { strStartsWith } from "../common/string/starts-with";
|
import { strStartsWith } from "../common/string/starts-with";
|
||||||
import { HomeAssistant, Context } from "../types";
|
import { HomeAssistant, Context } from "../types";
|
||||||
import { ManualAutomationConfig } from "./automation";
|
import {
|
||||||
|
BlueprintAutomationConfig,
|
||||||
|
ManualAutomationConfig,
|
||||||
|
} from "./automation";
|
||||||
|
|
||||||
interface BaseTraceStep {
|
interface BaseTraceStep {
|
||||||
path: string;
|
path: string;
|
||||||
@ -87,6 +90,7 @@ export interface AutomationTraceExtended extends AutomationTrace {
|
|||||||
trace: Record<string, ActionTraceStep[]>;
|
trace: Record<string, ActionTraceStep[]>;
|
||||||
context: Context;
|
context: Context;
|
||||||
config: ManualAutomationConfig;
|
config: ManualAutomationConfig;
|
||||||
|
blueprint_inputs?: BlueprintAutomationConfig;
|
||||||
error?: string;
|
error?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import {
|
|||||||
AutomationConfig,
|
AutomationConfig,
|
||||||
AutomationEntity,
|
AutomationEntity,
|
||||||
deleteAutomation,
|
deleteAutomation,
|
||||||
|
getAutomationConfig,
|
||||||
getAutomationEditorInitData,
|
getAutomationEditorInitData,
|
||||||
showAutomationEditor,
|
showAutomationEditor,
|
||||||
triggerAutomationActions,
|
triggerAutomationActions,
|
||||||
@ -303,39 +304,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
oldAutomationId !== this.automationId
|
oldAutomationId !== this.automationId
|
||||||
) {
|
) {
|
||||||
this._setEntityId();
|
this._setEntityId();
|
||||||
this.hass
|
this._loadConfig();
|
||||||
.callApi<AutomationConfig>(
|
|
||||||
"GET",
|
|
||||||
`config/automation/config/${this.automationId}`
|
|
||||||
)
|
|
||||||
.then(
|
|
||||||
(config) => {
|
|
||||||
// Normalize data: ensure trigger, action and condition are lists
|
|
||||||
// Happens when people copy paste their automations into the config
|
|
||||||
for (const key of ["trigger", "condition", "action"]) {
|
|
||||||
const value = config[key];
|
|
||||||
if (value && !Array.isArray(value)) {
|
|
||||||
config[key] = [value];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this._dirty = false;
|
|
||||||
this._config = config;
|
|
||||||
},
|
|
||||||
(resp) => {
|
|
||||||
showAlertDialog(this, {
|
|
||||||
text:
|
|
||||||
resp.status_code === 404
|
|
||||||
? this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.load_error_not_editable"
|
|
||||||
)
|
|
||||||
: this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.load_error_unknown",
|
|
||||||
"err_no",
|
|
||||||
resp.status_code
|
|
||||||
),
|
|
||||||
}).then(() => history.back());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changedProps.has("automationId") && !this.automationId && this.hass) {
|
if (changedProps.has("automationId") && !this.automationId && this.hass) {
|
||||||
@ -378,6 +347,36 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
this._entityId = automation?.entity_id;
|
this._entityId = automation?.entity_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _loadConfig() {
|
||||||
|
try {
|
||||||
|
const config = await getAutomationConfig(this.hass, this.automationId);
|
||||||
|
|
||||||
|
// Normalize data: ensure trigger, action and condition are lists
|
||||||
|
// Happens when people copy paste their automations into the config
|
||||||
|
for (const key of ["trigger", "condition", "action"]) {
|
||||||
|
const value = config[key];
|
||||||
|
if (value && !Array.isArray(value)) {
|
||||||
|
config[key] = [value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._dirty = false;
|
||||||
|
this._config = config;
|
||||||
|
} catch (err) {
|
||||||
|
showAlertDialog(this, {
|
||||||
|
text:
|
||||||
|
err.status_code === 404
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.load_error_not_editable"
|
||||||
|
)
|
||||||
|
: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.load_error_unknown",
|
||||||
|
"err_no",
|
||||||
|
err.status_code
|
||||||
|
),
|
||||||
|
}).then(() => history.back());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent<{ value: AutomationConfig }>) {
|
private _valueChanged(ev: CustomEvent<{ value: AutomationConfig }>) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
this._config = ev.detail.value;
|
this._config = ev.detail.value;
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
import { safeDump } from "js-yaml";
|
||||||
|
import {
|
||||||
|
customElement,
|
||||||
|
html,
|
||||||
|
LitElement,
|
||||||
|
property,
|
||||||
|
TemplateResult,
|
||||||
|
} from "lit-element";
|
||||||
|
import "../../../../components/ha-icon-button";
|
||||||
|
import "../../../../components/ha-code-editor";
|
||||||
|
import { HomeAssistant } from "../../../../types";
|
||||||
|
import { AutomationTraceExtended } from "../../../../data/trace";
|
||||||
|
|
||||||
|
@customElement("ha-automation-trace-blueprint-config")
|
||||||
|
export class HaAutomationTraceBlueprintConfig extends LitElement {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property() public trace!: AutomationTraceExtended;
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
return html`
|
||||||
|
<ha-code-editor
|
||||||
|
.value=${safeDump(this.trace.blueprint_inputs || "").trimRight()}
|
||||||
|
readOnly
|
||||||
|
></ha-code-editor>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-automation-trace-blueprint-config": HaAutomationTraceBlueprintConfig;
|
||||||
|
}
|
||||||
|
}
|
@ -39,6 +39,7 @@ import {
|
|||||||
mdiRefresh,
|
mdiRefresh,
|
||||||
mdiDownload,
|
mdiDownload,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
|
import "./ha-automation-trace-blueprint-config";
|
||||||
|
|
||||||
@customElement("ha-automation-trace")
|
@customElement("ha-automation-trace")
|
||||||
export class HaAutomationTrace extends LitElement {
|
export class HaAutomationTrace extends LitElement {
|
||||||
@ -70,7 +71,8 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
| "details"
|
| "details"
|
||||||
| "config"
|
| "config"
|
||||||
| "timeline"
|
| "timeline"
|
||||||
| "logbook" = "details";
|
| "logbook"
|
||||||
|
| "blueprint" = "details";
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
const stateObj = this._entityId
|
const stateObj = this._entityId
|
||||||
@ -197,6 +199,19 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
|
${this._trace.blueprint_inputs
|
||||||
|
? html`
|
||||||
|
<div
|
||||||
|
.view=${"blueprint"}
|
||||||
|
class=${classMap({
|
||||||
|
active: this._view === "blueprint",
|
||||||
|
})}
|
||||||
|
@click=${this._showTab}
|
||||||
|
>
|
||||||
|
Blueprint Config
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
${this._selected === undefined ||
|
${this._selected === undefined ||
|
||||||
this._logbookEntries === undefined ||
|
this._logbookEntries === undefined ||
|
||||||
@ -227,6 +242,13 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
.entries=${this._logbookEntries}
|
.entries=${this._logbookEntries}
|
||||||
></ha-logbook>
|
></ha-logbook>
|
||||||
`
|
`
|
||||||
|
: this._view === "blueprint"
|
||||||
|
? html`
|
||||||
|
<ha-automation-trace-blueprint-config
|
||||||
|
.hass=${this.hass}
|
||||||
|
.trace=${this._trace}
|
||||||
|
></ha-automation-trace-blueprint-config>
|
||||||
|
`
|
||||||
: html`
|
: html`
|
||||||
<ha-automation-trace-timeline
|
<ha-automation-trace-timeline
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user