diff --git a/packages/zwave-js/src/lib/controller/Controller.ts b/packages/zwave-js/src/lib/controller/Controller.ts index 06dc908f3ca6..afd81c250c86 100644 --- a/packages/zwave-js/src/lib/controller/Controller.ts +++ b/packages/zwave-js/src/lib/controller/Controller.ts @@ -122,6 +122,10 @@ import { ApplicationUpdateRequestNodeRemoved, ApplicationUpdateRequestSmartStartHomeIDReceived, } from "../serialapi/application/ApplicationUpdateRequest"; +import { + type SerialAPIStartedRequest, + SerialAPIWakeUpReason, +} from "../serialapi/application/SerialAPIStartedRequest"; import { ShutdownRequest, type ShutdownResponse, @@ -423,6 +427,10 @@ export class ZWaveController FunctionType.ReplaceFailedNode, this.handleReplaceNodeStatusReport.bind(this), ); + driver.registerRequestHandler( + FunctionType.SerialAPIStarted, + this.handleSerialAPIStartedUnexpectedly.bind(this), + ); } private _type: MaybeNotKnown; @@ -3848,6 +3856,33 @@ supported CCs: ${ } private _healNetworkProgress = new Map(); + /** + * Is called when the Serial API restart unexpectedly. + */ + private async handleSerialAPIStartedUnexpectedly( + msg: SerialAPIStartedRequest, + ): Promise { + // 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,