Skip to content

Commit

Permalink
fix: switch to 16 bit node IDs again when Serial API restarts unexpec…
Browse files Browse the repository at this point in the history
…tedly (#6271)
  • Loading branch information
AlCalzone committed Sep 21, 2023
1 parent 2e6f376 commit dec945b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/zwave-js/src/lib/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ import {
ApplicationUpdateRequestNodeRemoved,
ApplicationUpdateRequestSmartStartHomeIDReceived,
} from "../serialapi/application/ApplicationUpdateRequest";
import {
type SerialAPIStartedRequest,
SerialAPIWakeUpReason,
} from "../serialapi/application/SerialAPIStartedRequest";
import {
ShutdownRequest,
type ShutdownResponse,
Expand Down Expand Up @@ -423,6 +427,10 @@ export class ZWaveController
FunctionType.ReplaceFailedNode,
this.handleReplaceNodeStatusReport.bind(this),
);
driver.registerRequestHandler(
FunctionType.SerialAPIStarted,
this.handleSerialAPIStartedUnexpectedly.bind(this),
);
}

private _type: MaybeNotKnown<ZWaveLibraryTypes>;
Expand Down Expand Up @@ -3848,6 +3856,33 @@ supported CCs: ${
}

private _healNetworkProgress = new Map<number, HealNodeStatus>();
/**
* Is called when the Serial API restart unexpectedly.
*/
private async handleSerialAPIStartedUnexpectedly(
msg: SerialAPIStartedRequest,
): Promise<boolean> {
// Normally, the soft reset command includes waiting for this message. If we end up here, it is unexpected.

if (msg.wakeUpReason === SerialAPIWakeUpReason.SoftwareReset) {
// The Serial API restarted
if (this._nodeIdType === NodeIDType.Long) {
this.driver.controllerLog.print(
`Serial API restarted unexpectedly.`,
"warn",
);

// We previously used 16 bit node IDs, but the controller was reset.
// Remember this and try to go back to 16 bit.
this._nodeIdType = NodeIDType.Short;
await this.trySetNodeIDType(NodeIDType.Long);
}

return true; // Don't invoke any more handlers
}

return false; // Not handled
}

/**
* Performs a healing process for all alive nodes in the network,
Expand Down

0 comments on commit dec945b

Please sign in to comment.