From 587fb2a170abdc8207a6bf8fe54f63dabca015b0 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 8 Apr 2021 11:52:37 -0700 Subject: [PATCH] Add logbook note (#8843) Co-authored-by: Bram Kragten --- src/components/trace/hat-logbook-note.ts | 26 +++++++++ .../trace/ha-automation-trace-logbook.ts | 54 +++++++++++++++++++ .../trace/ha-automation-trace-path-details.ts | 18 ++++--- .../trace/ha-automation-trace-timeline.ts | 14 ++--- .../automation/trace/ha-automation-trace.ts | 7 +-- 5 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 src/components/trace/hat-logbook-note.ts create mode 100644 src/panels/config/automation/trace/ha-automation-trace-logbook.ts diff --git a/src/components/trace/hat-logbook-note.ts b/src/components/trace/hat-logbook-note.ts new file mode 100644 index 0000000000..5d5b1f9df7 --- /dev/null +++ b/src/components/trace/hat-logbook-note.ts @@ -0,0 +1,26 @@ +import { LitElement, css, html, customElement } from "lit-element"; + +@customElement("hat-logbook-note") +class HatLogbookNote extends LitElement { + render() { + return html` + Not all shown logbook entries might be related to this automation. + `; + } + + static styles = css` + :host { + display: block; + text-align: center; + font-style: italic; + padding: 16px; + margin-top: 8px; + } + `; +} + +declare global { + interface HTMLElementTagNameMap { + "hat-logbook-note": HatLogbookNote; + } +} diff --git a/src/panels/config/automation/trace/ha-automation-trace-logbook.ts b/src/panels/config/automation/trace/ha-automation-trace-logbook.ts new file mode 100644 index 0000000000..b18d83d1be --- /dev/null +++ b/src/panels/config/automation/trace/ha-automation-trace-logbook.ts @@ -0,0 +1,54 @@ +import { + css, + CSSResult, + customElement, + html, + LitElement, + property, + TemplateResult, +} from "lit-element"; +import type { HomeAssistant } from "../../../../types"; +import type { LogbookEntry } from "../../../../data/logbook"; +import "../../../../components/trace/hat-logbook-note"; +import "../../../logbook/ha-logbook"; + +@customElement("ha-automation-trace-logbook") +export class HaAutomationTraceLogbook extends LitElement { + @property({ attribute: false }) public hass!: HomeAssistant; + + @property({ type: Boolean, reflect: true }) public narrow!: boolean; + + @property({ attribute: false }) public logbookEntries!: LogbookEntry[]; + + protected render(): TemplateResult { + return this.logbookEntries.length + ? html` + + + ` + : html`
+ No Logbook entries found for this step. +
`; + } + + static get styles(): CSSResult[] { + return [ + css` + .padded-box { + padding: 16px; + } + `, + ]; + } +} + +declare global { + interface HTMLElementTagNameMap { + "ha-automation-trace-logbook": HaAutomationTraceLogbook; + } +} diff --git a/src/panels/config/automation/trace/ha-automation-trace-path-details.ts b/src/panels/config/automation/trace/ha-automation-trace-path-details.ts index b27edf9814..2416ea2ad6 100644 --- a/src/panels/config/automation/trace/ha-automation-trace-path-details.ts +++ b/src/panels/config/automation/trace/ha-automation-trace-path-details.ts @@ -9,6 +9,7 @@ import { property, TemplateResult, } from "lit-element"; +import { classMap } from "lit-html/directives/class-map"; import { ActionTraceStep, AutomationTraceExtended, @@ -18,11 +19,11 @@ import { import "../../../../components/ha-icon-button"; import "../../../../components/ha-code-editor"; import type { NodeInfo } from "../../../../components/trace/hat-graph"; +import "../../../../components/trace/hat-logbook-note"; import { HomeAssistant } from "../../../../types"; import { formatDateTimeWithSeconds } from "../../../../common/datetime/format_date_time"; import { LogbookEntry } from "../../../../data/logbook"; import { traceTabStyles } from "./styles"; -import { classMap } from "lit-html/directives/class-map"; import "../../../logbook/ha-logbook"; @customElement("ha-automation-trace-path-details") @@ -205,12 +206,15 @@ ${safeDump(trace.changed_variables).trimRight()}` + ? html` + + + ` : html`
No Logbook entries found for this step.
`; diff --git a/src/panels/config/automation/trace/ha-automation-trace-timeline.ts b/src/panels/config/automation/trace/ha-automation-trace-timeline.ts index 63599b2db5..b61ce862ee 100644 --- a/src/panels/config/automation/trace/ha-automation-trace-timeline.ts +++ b/src/panels/config/automation/trace/ha-automation-trace-timeline.ts @@ -7,19 +7,20 @@ import { property, TemplateResult, } from "lit-element"; -import { AutomationTraceExtended } from "../../../../data/trace"; -import { HomeAssistant } from "../../../../types"; -import { LogbookEntry } from "../../../../data/logbook"; +import type { AutomationTraceExtended } from "../../../../data/trace"; +import type { HomeAssistant } from "../../../../types"; +import type { LogbookEntry } from "../../../../data/logbook"; import "../../../../components/trace/hat-trace-timeline"; -import { NodeInfo } from "../../../../components/trace/hat-graph"; +import type { NodeInfo } from "../../../../components/trace/hat-graph"; +import "../../../../components/trace/hat-logbook-note"; @customElement("ha-automation-trace-timeline") export class HaAutomationTraceTimeline extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; - @property() public trace!: AutomationTraceExtended; + @property({ attribute: false }) public trace!: AutomationTraceExtended; - @property() public logbookEntries!: LogbookEntry[]; + @property({ attribute: false }) public logbookEntries!: LogbookEntry[]; @property() public selected!: NodeInfo; @@ -33,6 +34,7 @@ export class HaAutomationTraceTimeline extends LitElement { allowPick > + `; } diff --git a/src/panels/config/automation/trace/ha-automation-trace.ts b/src/panels/config/automation/trace/ha-automation-trace.ts index e319c36de4..e0a0cd1ce6 100644 --- a/src/panels/config/automation/trace/ha-automation-trace.ts +++ b/src/panels/config/automation/trace/ha-automation-trace.ts @@ -30,6 +30,7 @@ import { showAlertDialog } from "../../../../dialogs/generic/show-dialog-box"; import "./ha-automation-trace-path-details"; import "./ha-automation-trace-timeline"; import "./ha-automation-trace-config"; +import "./ha-automation-trace-logbook"; import { classMap } from "lit-html/directives/class-map"; import { traceTabStyles } from "./styles"; import { @@ -252,10 +253,10 @@ export class HaAutomationTrace extends LitElement { ` : this._view === "logbook" ? html` - + .logbookEntries=${this._logbookEntries} + > ` : this._view === "blueprint" ? html`