From e0bdef98a65777846a97b4678f2e2cc5557a1293 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 9 Sep 2020 22:10:23 +0200 Subject: [PATCH] Only show history tabs for certain domains (#6895) Co-authored-by: Zack Barett --- .../controls/more-info-automation.ts | 2 +- src/dialogs/more-info/ha-more-info-dialog.ts | 30 ++++++++++++++----- ...tab-history.ts => ha-more-info-history.ts} | 23 +++++++------- src/panels/logbook/ha-logbook.ts | 2 +- src/translations/en.json | 6 ++-- 5 files changed, 41 insertions(+), 22 deletions(-) rename src/dialogs/more-info/{ha-more-info-tab-history.ts => ha-more-info-history.ts} (89%) diff --git a/src/dialogs/more-info/controls/more-info-automation.ts b/src/dialogs/more-info/controls/more-info-automation.ts index a63a10d819..8b4ff441c2 100644 --- a/src/dialogs/more-info/controls/more-info-automation.ts +++ b/src/dialogs/more-info/controls/more-info-automation.ts @@ -55,7 +55,7 @@ class MoreInfoAutomation extends LitElement { justify-content: space-between; } .actions { - margin: 36px 0 8px 0; + margin: 8px 0; text-align: right; } `; diff --git a/src/dialogs/more-info/ha-more-info-dialog.ts b/src/dialogs/more-info/ha-more-info-dialog.ts index 7738ee7349..63381e3251 100644 --- a/src/dialogs/more-info/ha-more-info-dialog.ts +++ b/src/dialogs/more-info/ha-more-info-dialog.ts @@ -29,9 +29,19 @@ import { haStyleDialog } from "../../resources/styles"; import "../../state-summary/state-card-content"; import { HomeAssistant } from "../../types"; import { showConfirmationDialog } from "../generic/show-dialog-box"; +import "./ha-more-info-history"; import "./more-info-content"; const DOMAINS_NO_INFO = ["camera", "configurator"]; +const CONTROL_DOMAINS = [ + "light", + "media_player", + "vacuum", + "alarm_control_panel", + "climate", + "humidifier", + "weather", +]; const EDITABLE_DOMAINS_WITH_ID = ["scene", "automation"]; const EDITABLE_DOMAINS = ["script"]; @@ -127,7 +137,8 @@ export class MoreInfoDialog extends LitElement { ` : ""} - ${this._computeShowHistoryComponent(entityId) + ${CONTROL_DOMAINS.includes(domain) && + this._computeShowHistoryComponent(entityId) ? html` + ${!CONTROL_DOMAINS.includes(domain) || + !this._computeShowHistoryComponent(entityId) + ? "" + : html``} ${stateObj.attributes.restored ? html`

@@ -188,10 +206,10 @@ export class MoreInfoDialog extends LitElement { : ""} ` : html` - + > ` )} @@ -199,10 +217,6 @@ export class MoreInfoDialog extends LitElement { `; } - protected firstUpdated(): void { - import("./ha-more-info-tab-history"); - } - private _enlarge() { this.large = !this.large; } diff --git a/src/dialogs/more-info/ha-more-info-tab-history.ts b/src/dialogs/more-info/ha-more-info-history.ts similarity index 89% rename from src/dialogs/more-info/ha-more-info-tab-history.ts rename to src/dialogs/more-info/ha-more-info-history.ts index 18624a11ef..4c57bbd2c3 100644 --- a/src/dialogs/more-info/ha-more-info-tab-history.ts +++ b/src/dialogs/more-info/ha-more-info-history.ts @@ -16,11 +16,11 @@ import { getRecentWithCache } from "../../data/cached-history"; import { HistoryResult } from "../../data/history"; import { getLogbookData, LogbookEntry } from "../../data/logbook"; import "../../panels/logbook/ha-logbook"; -import { haStyleDialog } from "../../resources/styles"; +import { haStyle } from "../../resources/styles"; import { HomeAssistant } from "../../types"; -@customElement("ha-more-info-tab-history") -export class MoreInfoTabHistoryDialog extends LitElement { +@customElement("ha-more-info-history") +export class MoreInfoHistory extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @property() public entityId!: string; @@ -43,8 +43,7 @@ export class MoreInfoTabHistoryDialog extends LitElement { return html``; } - return html` - ` - : ""} - `; + : html`

+ ${this.hass.localize("ui.components.logbook.entries_not_found")} +
`}`; } protected firstUpdated(): void { @@ -139,13 +139,16 @@ export class MoreInfoTabHistoryDialog extends LitElement { static get styles() { return [ - haStyleDialog, + haStyle, css` state-history-charts { display: block; margin-bottom: 16px; } - + .no-entries { + text-align: center; + padding: 16px; + } ha-logbook { max-height: 360px; } @@ -161,6 +164,6 @@ export class MoreInfoTabHistoryDialog extends LitElement { declare global { interface HTMLElementTagNameMap { - "ha-more-info-tab-history": MoreInfoTabHistoryDialog; + "ha-more-info-history": MoreInfoHistory; } } diff --git a/src/panels/logbook/ha-logbook.ts b/src/panels/logbook/ha-logbook.ts index cf49dd24ba..2eb994cae1 100644 --- a/src/panels/logbook/ha-logbook.ts +++ b/src/panels/logbook/ha-logbook.ts @@ -67,7 +67,7 @@ class HaLogbook extends LitElement { if (!this.entries?.length) { return html`
- ${this.hass.localize("ui.panel.logbook.entries_not_found")} + ${this.hass.localize("ui.components.logbook.entries_not_found")}
`; } diff --git a/src/translations/en.json b/src/translations/en.json index 219471c422..24f05139cc 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -281,6 +281,9 @@ "error_required": "Required" }, "components": { + "logbook": { + "entries_not_found": "No logbook entries found." + }, "entity": { "entity-picker": { "entity": "Entity", @@ -401,7 +404,7 @@ "dismiss": "Dismiss dialog", "settings": "Entity settings", "edit": "Edit entity", - "controls": "Controls", + "details": "Details", "history": "History", "script": { "last_action": "Last Action", @@ -2045,7 +2048,6 @@ } }, "logbook": { - "entries_not_found": "No logbook entries found.", "ranges": { "today": "Today", "yesterday": "Yesterday",