diff --git a/src/data/otbr.ts b/src/data/otbr.ts index 604be8982a..8af577efd3 100644 --- a/src/data/otbr.ts +++ b/src/data/otbr.ts @@ -2,6 +2,7 @@ import { HomeAssistant } from "../types"; export interface OTBRInfo { active_dataset_tlvs: string; + border_agent_id: string; channel: number; extended_address: string; url: string; diff --git a/src/panels/config/integrations/integration-panels/thread/dialog-thread-dataset.ts b/src/panels/config/integrations/integration-panels/thread/dialog-thread-dataset.ts index b83c576840..cf022e8422 100644 --- a/src/panels/config/integrations/integration-panels/thread/dialog-thread-dataset.ts +++ b/src/panels/config/integrations/integration-panels/thread/dialog-thread-dataset.ts @@ -36,14 +36,8 @@ class DialogThreadDataset extends LitElement implements HassDialog { dataset.extended_pan_id && otbrInfo.active_dataset_tlvs?.includes(dataset.extended_pan_id); - const canImportKeychain = - hasOTBR && - this.hass.auth.external?.config.canTransferThreadCredentialsToKeychain && - network.routers?.length; - return html` @@ -59,28 +53,8 @@ class DialogThreadDataset extends LitElement implements HassDialog { Active dataset TLVs: ${otbrInfo.active_dataset_tlvs}` : nothing} - ${canImportKeychain - ? html`Send credentials to phone` - : nothing} `; } - - private _sendCredentials() { - this.hass.auth.external!.fireMessage({ - type: "thread/store_in_platform_keychain", - payload: { - mac_extended_address: - this._params?.network.dataset?.preferred_extended_address || - this._params!.network.routers![0]!.extended_address, - border_agent_id: - this._params?.network.dataset?.preferred_border_agent_id || - this._params!.network.routers![0]!.border_agent_id, - active_operational_dataset: this._params!.otbrInfo!.active_dataset_tlvs, - }, - }); - } } declare global { 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 e002c73f6c..3d99a4f9e3 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 @@ -160,6 +160,14 @@ export class ThreadConfigPanel extends SubscribeMixin(LitElement) { } private _renderNetwork(network: ThreadNetwork) { + const canImportKeychain = + this.hass.auth.external?.config.canTransferThreadCredentialsToKeychain && + network.dataset?.extended_pan_id && + this._otbrInfo && + this._otbrInfo?.active_dataset_tlvs?.includes( + network.dataset.extended_pan_id + ); + return html`
${network.name}${network.dataset @@ -303,9 +311,30 @@ export class ThreadConfigPanel extends SubscribeMixin(LitElement) { >
` : ""} + ${canImportKeychain + ? html`
+ Send credentials to phone +
` + : ""}
`; } + private _sendCredentials() { + if (!this._otbrInfo) { + return; + } + this.hass.auth.external!.fireMessage({ + type: "thread/store_in_platform_keychain", + payload: { + mac_extended_address: this._otbrInfo.extended_address, + border_agent_id: this._otbrInfo.border_agent_id ?? "", + active_operational_dataset: this._otbrInfo.active_dataset_tlvs ?? "", + }, + }); + } + private async _showDatasetInfo(ev: Event) { const network = (ev.currentTarget as any).network as ThreadNetwork; showThreadDatasetDialog(this, { network, otbrInfo: this._otbrInfo });