diff --git a/packages/zwave-js/bin/mock-server.js b/packages/zwave-js/bin/mock-server.cjs similarity index 96% rename from packages/zwave-js/bin/mock-server.js rename to packages/zwave-js/bin/mock-server.cjs index 355144973216..7d4d6a72fb2b 100755 --- a/packages/zwave-js/bin/mock-server.js +++ b/packages/zwave-js/bin/mock-server.cjs @@ -2,7 +2,7 @@ // @ts-check const { MockServer, createMockNodeOptionsFromDump } = require( - "../build/mockServer", + "../build/cjs/mockServer.js", ); const { readFileSync, statSync, readdirSync } = require("fs"); const path = require("path"); @@ -85,7 +85,7 @@ Each node ID may only be used once in mock configs. Node ID ${nodeConfig.id} is * @param {string} filename */ function getConfig(filename) { - if (filename.endsWith(".js")) { + if (filename.endsWith(".js") || filename.endsWith(".cjs")) { // The export can either be a static config object or a function that accepts a require let config = require(filename).default; if (typeof config === "function") { @@ -156,7 +156,7 @@ No config files found in ${absolutePath} const interfaceIndex = args.findIndex( (arg) => arg === "--interface" || arg === "-i", ); -const interface = interfaceIndex === -1 ? undefined : args[interfaceIndex + 1]; +const iface = interfaceIndex === -1 ? undefined : args[interfaceIndex + 1]; // Parse port const portIndex = args.findIndex((arg) => arg === "--port" || arg === "-p"); @@ -166,7 +166,7 @@ if (Number.isNaN(port)) port = undefined; let server; (async () => { server = new MockServer({ - interface, + interface: iface, port, config, }); diff --git a/packages/zwave-js/package.json b/packages/zwave-js/package.json index 34224c6f917d..f3c90e10c703 100644 --- a/packages/zwave-js/package.json +++ b/packages/zwave-js/package.json @@ -63,7 +63,7 @@ "build/**/package.json" ], "bin": { - "mock-server": "bin/mock-server.js" + "mock-server": "bin/mock-server.cjs" }, "author": { "name": "AlCalzone", diff --git a/server_config.cjs b/server_config.cjs new file mode 100644 index 000000000000..785c811ee4f2 --- /dev/null +++ b/server_config.cjs @@ -0,0 +1,58 @@ +// @ts-check +const { CommandClasses, ConfigValueFormat, SupervisionStatus } = require( + "@zwave-js/core", +); +const { ccCaps, MockZWaveFrameType, createMockZWaveRequestFrame } = require( + "@zwave-js/testing", +); +const { wait } = require("alcalzone-shared/async"); +const { + SupervisionCCGet, + SupervisionCCReport, + ConfigurationCCSet, + SwitchType, +} = require( + "zwave-js", +); + +/** @type {import("zwave-js/Testing").MockServerOptions["config"]} */ +module.exports.default = { + nodes: [ + { + id: 2, + capabilities: { + commandClasses: [ + CommandClasses.Version, + // CommandClasses.Supervision, + ccCaps({ + ccId: CommandClasses["Multilevel Switch"], + isSupported: true, + version: 4, + defaultValue: 0, + primarySwitchType: SwitchType["Down/Up"], + }), + ], + }, + // behaviors: [ + // { + // async handleCC(controller, self, receivedCC) { + // if ( + // receivedCC instanceof SupervisionCCGet + // && receivedCC.encapsulated + // instanceof ConfigurationCCSet + // ) { + // const cc = new SupervisionCCReport({ + // nodeId: controller.ownNodeId, + // sessionId: receivedCC.sessionId, + // moreUpdatesFollow: false, + // status: SupervisionStatus.Fail, + // }); + + // return { action: "sendCC", cc }; + // } + // }, + // }, + // ], + }, + ], +}; diff --git a/server_config.js b/server_config.js deleted file mode 100644 index eabf48f1cd14..000000000000 --- a/server_config.js +++ /dev/null @@ -1,72 +0,0 @@ -// @ts-check -const { CommandClasses, ConfigValueFormat, SupervisionStatus } = require( - "@zwave-js/core", -); -const { ccCaps, MockZWaveFrameType, createMockZWaveRequestFrame } = require( - "@zwave-js/testing", -); -const { wait } = require("alcalzone-shared/async"); -const { SupervisionCCGet, SupervisionCCReport, ConfigurationCCSet } = require( - "zwave-js", -); - -/** @type {import("zwave-js/Testing").MockServerOptions["config"]} */ -module.exports.default = { - nodes: [ - { - id: 2, - capabilities: { - commandClasses: [ - CommandClasses.Version, - CommandClasses.Supervision, - ccCaps({ - ccId: CommandClasses.Configuration, - isSupported: true, - version: 4, - parameters: [ - { - "#": 10, - valueSize: 1, - format: ConfigValueFormat.SignedInteger, - minValue: -128, - maxValue: 0, - defaultValue: 0, - name: "Test Param 1", - }, - { - "#": 255, - valueSize: 1, - format: ConfigValueFormat.BitField, - minValue: new Set([]), - maxValue: new Set([1, 4, 7]), - defaultValue: new Set([1]), - name: "Test Param 2", - info: "This is a description", - }, - ], - }), - ], - }, - behaviors: [ - { - async handleCC(controller, self, receivedCC) { - if ( - receivedCC instanceof SupervisionCCGet - && receivedCC.encapsulated - instanceof ConfigurationCCSet - ) { - const cc = new SupervisionCCReport({ - nodeId: controller.ownNodeId, - sessionId: receivedCC.sessionId, - moreUpdatesFollow: false, - status: SupervisionStatus.Fail, - }); - - return { action: "sendCC", cc }; - } - }, - }, - ], - }, - ], -}; diff --git a/yarn.lock b/yarn.lock index 476ba031e44f..b6c55db1de7b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10109,6 +10109,6 @@ __metadata: winston: "npm:^3.15.0" xstate: "npm:4.38.3" bin: - mock-server: bin/mock-server.js + mock-server: bin/mock-server.cjs languageName: unknown linkType: soft