diff --git a/packages/zwave-js/src/lib/controller/Controller.ts b/packages/zwave-js/src/lib/controller/Controller.ts index 45b1cf1cfceb..cf7cec802a01 100644 --- a/packages/zwave-js/src/lib/controller/Controller.ts +++ b/packages/zwave-js/src/lib/controller/Controller.ts @@ -1295,26 +1295,11 @@ export class ZWaveController // ignore the initVersion, no clue what to do with it // fetch the list of long range nodes until the controller reports no more - const lrNodeIds: Array = []; + const lrNodeIds = await this.getLongRangeNodes(); let lrChannel : LongRangeChannel | undefined; const maxPayloadSize = await this.getMaxPayloadSize(); let maxPayloadSizeLR : number | undefined; if (this.isLongRange()) { - const segment = 0; - while (true) { - const nodesResponse = await this.driver.sendMessage< - GetLongRangeNodesResponse - >( - new GetLongRangeNodesRequest(this.driver, { - segmentNumber: segment, - }), - ); - lrNodeIds.push(...nodesResponse.nodeIds); - if (!nodesResponse.moreNodes) { - break; - } - } - // TODO: restore/set the channel const lrChannelResp = await this.driver.sendMessage(new GetLongRangeChannelRequest(this.driver)); lrChannel = lrChannelResp.longRangeChannel; @@ -1480,6 +1465,33 @@ export class ZWaveController ); } + /** + * Gets the list of long range nodes from the controller. + * Warning: This only works when followed up by a hard-reset, so don't call this directly + * @internal + */ + public async getLongRangeNodes(): Promise> { + const nodeIds: Array = []; + + if (this.isLongRange()) { + const segment = 0; + while (true) { + const nodesResponse = await this.driver.sendMessage< + GetLongRangeNodesResponse + >( + new GetLongRangeNodesRequest(this.driver, { + segmentNumber: segment, + }), + ); + nodeIds.push(...nodesResponse.nodeIds); + if (!nodesResponse.moreNodes) { + break; + } + } + } + return nodeIds; + } + /** * Sets the NIF of the controller to the Gateway device type and to include the CCs supported by Z-Wave JS. * Warning: This only works when followed up by a hard-reset, so don't call this directly