From 70f9f6570ec6ec0f68ab484b58365a537b601ffc Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 20 Jan 2023 08:29:48 -0500 Subject: [PATCH 1/3] Show Thread panel on thread config entry --- src/panels/config/integrations/ha-integration-card.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/panels/config/integrations/ha-integration-card.ts b/src/panels/config/integrations/ha-integration-card.ts index 5fa1fba1d1a6..cedf0c214a9f 100644 --- a/src/panels/config/integrations/ha-integration-card.ts +++ b/src/panels/config/integrations/ha-integration-card.ts @@ -75,11 +75,11 @@ import type { ConfigEntryExtended } from "./ha-config-integrations"; import "./ha-integration-header"; const integrationsWithPanel = { + matter: "/config/matter", mqtt: "/config/mqtt", + thread: "/config/thread", zha: "/config/zha/dashboard", zwave_js: "/config/zwave_js/dashboard", - matter: "/config/matter", - otbr: "/config/thread", }; @customElement("ha-integration-card") From bbf81ba5c1a64b9a0dab22e2166ce4b10ecac779 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 20 Jan 2023 08:32:12 -0500 Subject: [PATCH 2/3] Rename data file to use right domain --- src/data/{thread.ts => otbr.ts} | 4 ++-- .../integration-panels/thread/thread-config-panel.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) rename src/data/{thread.ts => otbr.ts} (56%) diff --git a/src/data/thread.ts b/src/data/otbr.ts similarity index 56% rename from src/data/thread.ts rename to src/data/otbr.ts index e58111ee12e4..23bf15710249 100644 --- a/src/data/thread.ts +++ b/src/data/otbr.ts @@ -1,11 +1,11 @@ import { HomeAssistant } from "../types"; -export interface ThreadInfo { +export interface OTBRInfo { url: string; active_dataset_tlvs: string; } -export const threadGetInfo = (hass: HomeAssistant): Promise => +export const getOTBRInfo = (hass: HomeAssistant): Promise => hass.callWS({ type: "otbr/info", }); diff --git a/src/panels/config/integrations/integration-panels/thread/thread-config-panel.ts b/src/panels/config/integrations/integration-panels/thread/thread-config-panel.ts index 138318511e61..aed8b3c2bb6d 100644 --- a/src/panels/config/integrations/integration-panels/thread/thread-config-panel.ts +++ b/src/panels/config/integrations/integration-panels/thread/thread-config-panel.ts @@ -5,7 +5,7 @@ import "../../../../../components/ha-card"; import "../../../../../layouts/hass-subpage"; import { haStyle } from "../../../../../resources/styles"; import { HomeAssistant } from "../../../../../types"; -import { threadGetInfo, ThreadInfo } from "../../../../../data/thread"; +import { getOTBRInfo, OTBRInfo } from "../../../../../data/otbr"; @customElement("thread-config-panel") export class ThreadConfigPanel extends LitElement { @@ -13,7 +13,7 @@ export class ThreadConfigPanel extends LitElement { @property({ type: Boolean }) public narrow!: boolean; - @state() private _info?: ThreadInfo; + @state() private _info?: OTBRInfo; protected render(): TemplateResult { return html` @@ -45,7 +45,7 @@ export class ThreadConfigPanel extends LitElement { protected override firstUpdated(changedProps: PropertyValues) { super.firstUpdated(changedProps); - threadGetInfo(this.hass).then((info) => { + getOTBRInfo(this.hass).then((info) => { this._info = info; }); } From 56fd473bebec131bf1163a9e8e08c196e4bb6099 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 20 Jan 2023 08:41:24 -0500 Subject: [PATCH 3/3] Make panel a bit more pleasant --- .../thread/thread-config-panel.ts | 70 ++++++++++++++----- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/thread/thread-config-panel.ts b/src/panels/config/integrations/integration-panels/thread/thread-config-panel.ts index aed8b3c2bb6d..78ed4c91b578 100644 --- a/src/panels/config/integrations/integration-panels/thread/thread-config-panel.ts +++ b/src/panels/config/integrations/integration-panels/thread/thread-config-panel.ts @@ -6,6 +6,8 @@ import "../../../../../layouts/hass-subpage"; import { haStyle } from "../../../../../resources/styles"; import { HomeAssistant } from "../../../../../types"; import { getOTBRInfo, OTBRInfo } from "../../../../../data/otbr"; +import { isComponentLoaded } from "../../../../../common/config/is_component_loaded"; +import { showConfigFlowDialog } from "../../../../../dialogs/config-flow/show-dialog-config-flow"; @customElement("thread-config-panel") export class ThreadConfigPanel extends LitElement { @@ -19,23 +21,37 @@ export class ThreadConfigPanel extends LitElement { return html`
- -
- ${!this._info - ? html`` - : html` - - - - - - - - - -
URL${this._info.url}
Active Dataset TLVs${this._info.active_dataset_tlvs || "-"}
- `} -
+ + ${isComponentLoaded(this.hass, "otbr") + ? html` +
+ ${!this._info + ? html`` + : html` + + + + + + + + + +
URL${this._info.url}
Active Dataset TLVs${this._info.active_dataset_tlvs || "-"}
+ `} +
+ ` + : html` +
No border routers found.
+
+ +
+ `}
@@ -45,8 +61,24 @@ export class ThreadConfigPanel extends LitElement { protected override firstUpdated(changedProps: PropertyValues) { super.firstUpdated(changedProps); - getOTBRInfo(this.hass).then((info) => { - this._info = info; + this._refresh(); + } + + private _refresh() { + if (isComponentLoaded(this.hass, "otbr")) { + getOTBRInfo(this.hass).then((info) => { + this._info = info; + }); + } + } + + private _addOTBR() { + showConfigFlowDialog(this, { + dialogClosedCallback: () => { + this._refresh(); + }, + startFlowHandler: "otbr", + showAdvanced: this.hass.userData?.showAdvanced, }); }