diff --git a/packages/zwave-js/src/mockServer.ts b/packages/zwave-js/src/mockServer.ts index 006e1046d75d..2eb1a4904aad 100644 --- a/packages/zwave-js/src/mockServer.ts +++ b/packages/zwave-js/src/mockServer.ts @@ -35,12 +35,19 @@ export type MockServerNodeOptions = & { behaviors?: MockNodeBehavior[]; }; + +export type MockServerInitHook = ( + controller: MockController, + nodes: MockNode[], +) => void; + export interface MockServerOptions { interface?: string; port?: number; config?: { controller?: MockServerControllerOptions; nodes?: MockServerNodeOptions[]; + onInit?: MockServerInitHook; }; } @@ -70,6 +77,11 @@ export class MockServer { this.options.config?.nodes, )); + // Call the init hook if it is defined + if (typeof this.options.config?.onInit === "function") { + this.options.config.onInit(this.mockController, this.mockNodes); + } + // Start a TCP server, listen for connections, and forward them to the serial port this.server = createServer((socket) => { if (!this.serialport) {