Skip to content

Commit

Permalink
feat(longrange): move fetching LR nodes to a helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
jtbraun committed Nov 15, 2023
1 parent 7b268b4 commit 1bb54b2
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions packages/zwave-js/src/lib/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> = [];
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<GetLongRangeChannelResponse>(new GetLongRangeChannelRequest(this.driver));
lrChannel = lrChannelResp.longRangeChannel;
Expand Down Expand Up @@ -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<Array<number>> {
const nodeIds: Array<number> = [];

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
Expand Down

0 comments on commit 1bb54b2

Please sign in to comment.