-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow storing thread credentials in phone keychain
- Loading branch information
1 parent
43a422c
commit aa34f22
Showing
4 changed files
with
123 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/panels/config/integrations/integration-panels/thread/dialog-thread-dataset.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { LitElement, html, nothing } from "lit"; | ||
import { customElement, property, state } from "lit/decorators"; | ||
import { fireEvent } from "../../../../../common/dom/fire_event"; | ||
import { HassDialog } from "../../../../../dialogs/make-dialog-manager"; | ||
import { HomeAssistant } from "../../../../../types"; | ||
import { DialogThreadDatasetParams } from "./show-dialog-thread-dataset"; | ||
import { createCloseHeading } from "../../../../../components/ha-dialog"; | ||
|
||
@customElement("ha-dialog-thread-dataset") | ||
class DialogThreadDataset extends LitElement implements HassDialog { | ||
@property({ attribute: false }) public hass!: HomeAssistant; | ||
|
||
@state() private _params?: DialogThreadDatasetParams; | ||
|
||
public async showDialog( | ||
params: DialogThreadDatasetParams | ||
): Promise<Promise<void>> { | ||
this._params = params; | ||
} | ||
|
||
public closeDialog(): void { | ||
this._params = undefined; | ||
fireEvent(this, "dialog-closed", { dialog: this.localName }); | ||
} | ||
|
||
protected render() { | ||
if (!this._params) { | ||
return nothing; | ||
} | ||
const network = this._params.network; | ||
const dataset = network.dataset!; | ||
const otbrInfo = this._params.otbrInfo; | ||
|
||
const hasOTBR = | ||
otbrInfo && | ||
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`<ha-dialog | ||
open | ||
.hideActions=${!canImportKeychain} | ||
@closed=${this.closeDialog} | ||
.heading=${createCloseHeading(this.hass, network.name)} | ||
> | ||
<div> | ||
Network name: ${dataset.network_name}<br /> | ||
Channel: ${dataset.channel}<br /> | ||
Dataset id: ${dataset.dataset_id}<br /> | ||
Pan id: ${dataset.pan_id}<br /> | ||
Extended Pan id: ${dataset.extended_pan_id}<br /> | ||
${hasOTBR | ||
? html`OTBR URL: ${otbrInfo.url}<br /> | ||
Active dataset TLVs: ${otbrInfo.active_dataset_tlvs}` | ||
: nothing} | ||
</div> | ||
${canImportKeychain | ||
? html`<ha-button slot="primary-action" @click=${this._sendCredentials} | ||
>Send credentials to phone</ha-button | ||
>` | ||
: nothing} | ||
</ha-dialog>`; | ||
} | ||
|
||
private _sendCredentials() { | ||
this.hass.auth.external!.fireMessage({ | ||
type: "thread/store_in_platform_keychain", | ||
payload: { | ||
mac_extended_address: | ||
this._params!.network.routers![0]!.extended_pan_id, | ||
border_agent_id: this._params!.network.routers![0]!.border_agent_id, | ||
active_operational_dataset: this._params!.otbrInfo!.active_dataset_tlvs, | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ha-dialog-thread-dataset": DialogThreadDataset; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/panels/config/integrations/integration-panels/thread/show-dialog-thread-dataset.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fireEvent } from "../../../../../common/dom/fire_event"; | ||
import { OTBRInfo } from "../../../../../data/otbr"; | ||
import { ThreadNetwork } from "./thread-config-panel"; | ||
|
||
export interface DialogThreadDatasetParams { | ||
network: ThreadNetwork; | ||
otbrInfo?: OTBRInfo; | ||
} | ||
|
||
export const showThreadDatasetDialog = ( | ||
element: HTMLElement, | ||
dialogParams: DialogThreadDatasetParams | ||
): void => { | ||
fireEvent(element, "show-dialog", { | ||
dialogTag: "ha-dialog-thread-dataset", | ||
dialogImport: () => import("./dialog-thread-dataset"), | ||
dialogParams, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters