Skip to content

Commit

Permalink
ZwaveJS: Handle S2 inclusion via Inclusion Controller (#23100)
Browse files Browse the repository at this point in the history
  • Loading branch information
MindFreeze authored Dec 6, 2024
1 parent af04927 commit e02736b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/data/zwave_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -808,6 +813,21 @@ export const subscribeZwaveNodeStatistics = (
}
);

export const subscribeS2Inclusion = (
hass: HomeAssistant,
entry_id: string,
callbackFunction: (
message: ZWaveJSS2InclusionValidateDskAndEnterPinMessage
) => void
): Promise<UnsubscribeFunc> =>
hass.connection.subscribeMessage(
(message: any) => callbackFunction(message),
{
type: "zwave_js/subscribe_s2_inclusion",
entry_id,
}
);

export const fetchZwaveIsNodeFirmwareUpdateInProgress = (
hass: HomeAssistant,
device_id: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,21 @@ class DialogZWaveJSAddNode extends LitElement {
}

public async showDialog(params: ZWaveJSAddNodeDialogParams): Promise<void> {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fireEvent } from "../../../../../common/dom/fire_event";

export interface ZWaveJSAddNodeDialogParams {
entry_id: string;
dsk?: string;
onStop?: () => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
fetchZwaveProvisioningEntries,
InclusionState,
setZwaveDataCollectionPreference,
subscribeS2Inclusion,
subscribeZwaveControllerStatistics,
} from "../../../../../data/zwave_js";
import { showOptionsFlowDialog } from "../../../../../dialogs/config-flow/show-dialog-options-flow";
Expand Down Expand Up @@ -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),
});
}),
];
}

Expand Down

0 comments on commit e02736b

Please sign in to comment.