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 e58111ee12..23bf157102 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/ha-integration-card.ts b/src/panels/config/integrations/ha-integration-card.ts index 5fa1fba1d1..cedf0c214a 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") 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 138318511e..78ed4c91b5 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,9 @@ 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"; +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 { @@ -13,29 +15,43 @@ export class ThreadConfigPanel extends LitElement { @property({ type: Boolean }) public narrow!: boolean; - @state() private _info?: ThreadInfo; + @state() private _info?: OTBRInfo; protected render(): TemplateResult { 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); - threadGetInfo(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, }); }