diff --git a/src/data/zwave_js.ts b/src/data/zwave_js.ts index 4bfe98acf5ff..952804522f29 100644 --- a/src/data/zwave_js.ts +++ b/src/data/zwave_js.ts @@ -398,6 +398,11 @@ export interface ZWaveJSRemovedNode { label: string; } +export interface ZWaveJSS2InclusionValidateDskAndEnterPinMessage { + event: "validate dsk and enter pin"; + dsk: string; +} + export const enum NodeStatus { Unknown, Asleep, @@ -808,6 +813,21 @@ export const subscribeZwaveNodeStatistics = ( } ); +export const subscribeS2Inclusion = ( + hass: HomeAssistant, + entry_id: string, + callbackFunction: ( + message: ZWaveJSS2InclusionValidateDskAndEnterPinMessage + ) => void +): Promise => + hass.connection.subscribeMessage( + (message: any) => callbackFunction(message), + { + type: "zwave_js/subscribe_s2_inclusion", + entry_id, + } + ); + export const fetchZwaveIsNodeFirmwareUpdateInProgress = ( hass: HomeAssistant, device_id: string diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-add-node.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-add-node.ts index 2e4a3ccc2500..c7a3ccddcafa 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-add-node.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-add-node.ts @@ -105,11 +105,21 @@ class DialogZWaveJSAddNode extends LitElement { } public async showDialog(params: ZWaveJSAddNodeDialogParams): Promise { + if (this._status) { + // already started + return; + } this._params = params; this._entryId = params.entry_id; this._status = "loading"; this._checkSmartStartSupport(); - this._startInclusion(); + if (params.dsk) { + this._status = "validate_dsk_enter_pin"; + this._dsk = params.dsk; + this._startInclusion(undefined, params.dsk); + } else { + this._startInclusion(); + } } @query("#pin-input") private _pinInput?: HaTextField; diff --git a/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-add-node.ts b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-add-node.ts index 6c4c3b38f864..27ef0ccd87a4 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-add-node.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-add-node.ts @@ -2,6 +2,7 @@ import { fireEvent } from "../../../../../common/dom/fire_event"; export interface ZWaveJSAddNodeDialogParams { entry_id: string; + dsk?: string; onStop?: () => void; } diff --git a/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts b/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts index 3cf0d53c69f5..0ecf4ba74ad0 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts @@ -36,6 +36,7 @@ import { fetchZwaveProvisioningEntries, InclusionState, setZwaveDataCollectionPreference, + subscribeS2Inclusion, subscribeZwaveControllerStatistics, } from "../../../../../data/zwave_js"; import { showOptionsFlowDialog } from "../../../../../dialogs/config-flow/show-dialog-options-flow"; @@ -102,6 +103,13 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) { this._statistics = message; } ), + subscribeS2Inclusion(this.hass, this.configEntryId, (message) => { + showZWaveJSAddNodeDialog(this, { + entry_id: this.configEntryId, + dsk: message.dsk, + onStop: () => setTimeout(() => this._fetchData(), 100), + }); + }), ]; }