From ad51d313a187d8693b5a3e4657965735d58e7761 Mon Sep 17 00:00:00 2001
From: karwosts <32912880+karwosts@users.noreply.github.com>
Date: Wed, 27 Sep 2023 05:26:25 -0700
Subject: [PATCH] Debug option to enable logging server calls (#17956)
---
src/fake_data/provide_hass.ts | 1 +
.../debug/developer-tools-debug.ts | 52 +++++++++++++++++++
.../debug/ha-debug-connection-row.ts | 50 ++++++++++++++++++
.../developer-tools/developer-tools-router.ts | 4 ++
.../ha-panel-developer-tools.ts | 23 ++++++++
src/state/connection-mixin.ts | 11 ++--
src/translations/en.json | 7 +++
src/types.ts | 1 +
src/util/ha-pref-storage.ts | 1 +
9 files changed, 145 insertions(+), 5 deletions(-)
create mode 100644 src/panels/developer-tools/debug/developer-tools-debug.ts
create mode 100644 src/panels/developer-tools/debug/ha-debug-connection-row.ts
diff --git a/src/fake_data/provide_hass.ts b/src/fake_data/provide_hass.ts
index 297f4d4f8c..111ebf6e31 100644
--- a/src/fake_data/provide_hass.ts
+++ b/src/fake_data/provide_hass.ts
@@ -271,6 +271,7 @@ export const provideHass = (
},
dockedSidebar: "auto",
vibrate: true,
+ debugConnection: false,
suspendWhenHidden: false,
moreInfoEntityId: null as any,
// @ts-ignore
diff --git a/src/panels/developer-tools/debug/developer-tools-debug.ts b/src/panels/developer-tools/debug/developer-tools-debug.ts
new file mode 100644
index 0000000000..6a5aa730cd
--- /dev/null
+++ b/src/panels/developer-tools/debug/developer-tools-debug.ts
@@ -0,0 +1,52 @@
+import { CSSResultGroup, LitElement, css, html } from "lit";
+import { customElement, property } from "lit/decorators";
+import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
+import { haStyle } from "../../../resources/styles";
+import { HomeAssistant } from "../../../types";
+import "./ha-debug-connection-row";
+
+@customElement("developer-tools-debug")
+class HaPanelDevDebug extends SubscribeMixin(LitElement) {
+ @property({ attribute: false }) public hass!: HomeAssistant;
+
+ @property({ type: Boolean }) public narrow!: boolean;
+
+ protected render() {
+ return html`
+
+
+
+
+
+
+ `;
+ }
+
+ static get styles(): CSSResultGroup {
+ return [
+ haStyle,
+ css`
+ .content {
+ padding: 28px 20px 16px;
+ display: block;
+ max-width: 600px;
+ margin: 0 auto;
+ }
+ `,
+ ];
+ }
+}
+
+declare global {
+ interface HTMLElementTagNameMap {
+ "developer-tools-debug": HaPanelDevDebug;
+ }
+}
diff --git a/src/panels/developer-tools/debug/ha-debug-connection-row.ts b/src/panels/developer-tools/debug/ha-debug-connection-row.ts
new file mode 100644
index 0000000000..e4b1c5c3ff
--- /dev/null
+++ b/src/panels/developer-tools/debug/ha-debug-connection-row.ts
@@ -0,0 +1,50 @@
+import { html, LitElement, TemplateResult } from "lit";
+import { customElement, property } from "lit/decorators";
+import "../../../components/ha-settings-row";
+import "../../../components/ha-switch";
+import type { HaSwitch } from "../../../components/ha-switch";
+import type { HomeAssistant } from "../../../types";
+import { storeState } from "../../../util/ha-pref-storage";
+
+@customElement("ha-debug-connection-row")
+class HaDebugConnectionRow extends LitElement {
+ @property({ attribute: false }) public hass!: HomeAssistant;
+
+ @property() public narrow!: boolean;
+
+ protected render(): TemplateResult {
+ return html`
+
+
+ ${this.hass.localize(
+ "ui.panel.developer-tools.tabs.debug.debug_connection.title"
+ )}
+
+
+ ${this.hass.localize(
+ "ui.panel.developer-tools.tabs.debug.debug_connection.description"
+ )}
+
+
+
+ `;
+ }
+
+ private async _checkedChanged(ev: Event) {
+ const debugConnection = (ev.target as HaSwitch).checked;
+ if (debugConnection === this.hass.debugConnection) {
+ return;
+ }
+ this.hass.debugConnection = debugConnection;
+ storeState(this.hass);
+ }
+}
+
+declare global {
+ interface HTMLElementTagNameMap {
+ "ha-debug-connection-row": HaDebugConnectionRow;
+ }
+}
diff --git a/src/panels/developer-tools/developer-tools-router.ts b/src/panels/developer-tools/developer-tools-router.ts
index 5b8baf3899..72b9795a2c 100644
--- a/src/panels/developer-tools/developer-tools-router.ts
+++ b/src/panels/developer-tools/developer-tools-router.ts
@@ -49,6 +49,10 @@ class DeveloperToolsRouter extends HassRouterPage {
tag: "developer-tools-assist",
load: () => import("./assist/developer-tools-assist"),
},
+ debug: {
+ tag: "developer-tools-debug",
+ load: () => import("./debug/developer-tools-debug"),
+ },
},
};
diff --git a/src/panels/developer-tools/ha-panel-developer-tools.ts b/src/panels/developer-tools/ha-panel-developer-tools.ts
index 813cc014e7..de7ec5777c 100644
--- a/src/panels/developer-tools/ha-panel-developer-tools.ts
+++ b/src/panels/developer-tools/ha-panel-developer-tools.ts
@@ -1,9 +1,14 @@
+import { mdiDotsVertical } from "@mdi/js";
import "@polymer/paper-tabs/paper-tab";
import "@polymer/paper-tabs/paper-tabs";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
+import type { ActionDetail } from "@material/mwc-list";
import { navigate } from "../../common/navigate";
import "../../components/ha-menu-button";
+import "../../components/ha-button-menu";
+import "../../components/ha-icon-button";
+import "../../components/ha-list-item";
import { haStyle } from "../../resources/styles";
import { HomeAssistant, Route } from "../../types";
import "./developer-tools-router";
@@ -34,6 +39,16 @@ class PanelDeveloperTools extends LitElement {
${this.hass.localize("panel.developer_tools")}
+
+
+
+ ${this.hass.localize("ui.panel.developer-tools.tabs.debug.title")}
+
+