-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow storing thread credentials in phone keychain #20743
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a confirmation (alert, toast notification) when it's done? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iOS currently has a circle checkmark that appears in the middle of the screen when it completes. |
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? I think @bgoncal said iOS uses the extended mac address as the border_agent_id. My understanding is that the iOS app is only looking for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But android will use the border agent id most probably |
||
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 { | ||
interface HTMLElementTagNameMap { | ||
"ha-dialog-thread-dataset": DialogThreadDataset; | ||
} | ||
} |
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, | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't have "!", right?