From 678c476cb1bd2fcb88ecd4d149e16e321df6f47a Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 21 Oct 2024 14:58:25 +0200 Subject: [PATCH] test: fix several tests --- packages/cc/src/lib/CommandClass.ts | 2 +- .../src/lib/test/cc/AssociationCC.test.ts | 21 ++-- .../test/cc/AssociationGroupInfoCC.test.ts | 40 +++---- .../zwave-js/src/lib/test/cc/BasicCC.test.ts | 34 +++--- .../src/lib/test/cc/BatteryCC.test.ts | 64 +++++------ .../src/lib/test/cc/BinarySensorCC.test.ts | 40 +++---- .../src/lib/test/cc/BinarySwitchCC.test.ts | 32 +++--- .../zwave-js/src/lib/test/cc/CRC16CC.test.ts | 20 ++-- .../src/lib/test/cc/CentralSceneCC.test.ts | 50 ++++----- .../src/lib/test/cc/ColorSwitchCC.test.ts | 31 +++--- .../cc/CommandClass.persistValues.test.ts | 13 +-- .../src/lib/test/cc/CommandClass.test.ts | 24 ++--- .../src/lib/test/cc/DoorLockCC.test.ts | 81 +++++++------- .../src/lib/test/cc/DoorLockLoggingCC.test.ts | 21 ++-- .../src/lib/test/cc/EntryControlCC.test.ts | 33 +++--- .../zwave-js/src/lib/test/cc/FibaroCC.test.ts | 33 +++--- .../HumidityControlOperatingStateCC.test.ts | 11 +- .../src/lib/test/cc/IndicatorCC.test.ts | 29 +++-- .../src/lib/test/cc/LanguageCC.test.ts | 30 +++--- .../test/cc/ManufacturerSpecificCC.test.ts | 11 +- .../zwave-js/src/lib/test/cc/MeterCC.test.ts | 100 +++++++++--------- .../test/cc/MultiChannelAssociationCC.test.ts | 41 +++---- .../src/lib/test/cc/MultiChannelCC.test.ts | 11 +- .../lib/test/cc/MultilevelSwitchCC.test.ts | 30 +++--- .../src/lib/test/cc/PowerlevelCC.test.ts | 30 +++--- .../src/lib/test/cc/SceneActivationCC.test.ts | 20 ++-- .../cc/SceneActuatorConfigurationCC.test.ts | 20 ++-- .../cc/SceneControllerConfigurationCC.test.ts | 20 ++-- .../lib/test/cc/ThermostatFanModeCC.test.ts | 11 +- .../lib/test/cc/ThermostatFanStateCC.test.ts | 20 ++-- .../zwave-js/src/lib/test/cc/TimeCC.test.ts | 30 +++--- 31 files changed, 474 insertions(+), 479 deletions(-) diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 992cd45f879a..c3f1cbb21b99 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -286,7 +286,7 @@ export class CommandClass implements CCId { public static from(raw: CCRaw, ctx: CCParsingContext): CommandClass { // FIXME: Propagate frame type etc. // FIXME: Refactor subclasses' parse() to override this - return new CommandClass({ + return new this({ nodeId: ctx.ownNodeId, ccId: raw.ccId, ccCommand: raw.ccCommand, diff --git a/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts b/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts index 06a44672522f..dd74763c5d38 100644 --- a/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts @@ -6,6 +6,7 @@ import { AssociationCCSupportedGroupingsGet, AssociationCCSupportedGroupingsReport, AssociationCommand, + CommandClass, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; import test from "ava"; @@ -38,11 +39,11 @@ test("the SupportedGroupingsReport command should be deserialized correctly", (t 7, // # of groups ]), ); - const cc = new AssociationCCSupportedGroupingsReport({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as AssociationCCSupportedGroupingsReport; + t.is(cc.constructor, AssociationCCSupportedGroupingsReport); t.is(cc.groupCount, 7); }); @@ -92,11 +93,11 @@ test("the Report command should be deserialized correctly", (t) => { 5, ]), ); - const cc = new AssociationCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as AssociationCCReport; + t.is(cc.constructor, AssociationCCReport); t.is(cc.groupId, 5); t.is(cc.maxNodes, 9); diff --git a/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts b/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts index 0bf177f9dda6..3e924a7af981 100644 --- a/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts @@ -9,6 +9,7 @@ import { AssociationGroupInfoCommand, AssociationGroupInfoProfile, BasicCommand, + CommandClass, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; import test from "ava"; @@ -51,11 +52,11 @@ test("the NameReport command should be deserialized correctly", (t) => { 0x72, ]), ); - const cc = new AssociationGroupInfoCCNameReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as AssociationGroupInfoCCNameReport; + t.is(cc.constructor, AssociationGroupInfoCCNameReport); t.is(cc.groupId, 7); t.is(cc.name, "foobar"); @@ -138,11 +139,11 @@ test("the Info Report command should be deserialized correctly", (t) => { 0, ]), ); - const cc = new AssociationGroupInfoCCInfoReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as AssociationGroupInfoCCInfoReport; + t.is(cc.constructor, AssociationGroupInfoCCInfoReport); t.is(cc.groups.length, 2); t.is(cc.groups[0].groupId, 1); @@ -184,11 +185,11 @@ test("the CommandListReport command should be deserialized correctly", (t) => { 0x05, ]), ); - const cc = new AssociationGroupInfoCCCommandListReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as AssociationGroupInfoCCCommandListReport; + t.is(cc.constructor, AssociationGroupInfoCCCommandListReport); t.is(cc.groupId, 7); t.is(cc.commands.size, 2); @@ -203,11 +204,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new AssociationGroupInfoCC({ - nodeId: 1, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 1 } as any, + ) as AssociationGroupInfoCC; t.is(cc.constructor, AssociationGroupInfoCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts b/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts index 2780b0928c66..96a98ae1e285 100644 --- a/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts @@ -5,6 +5,7 @@ import { BasicCCSet, type BasicCCValues, BasicCommand, + CommandClass, getCCValues, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; @@ -55,11 +56,11 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 55, // current value ]), ); - const basicCC = new BasicCCReport({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const basicCC = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as BasicCCReport; + t.is(basicCC.constructor, BasicCCReport); t.is(basicCC.currentValue, 55); t.is(basicCC.targetValue, undefined); @@ -75,11 +76,11 @@ test("the Report command (v2) should be deserialized correctly", (t) => { 1, // duration ]), ); - const basicCC = new BasicCCReport({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const basicCC = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as BasicCCReport; + t.is(basicCC.constructor, BasicCCReport); t.is(basicCC.currentValue, 55); t.is(basicCC.targetValue, 66); @@ -91,11 +92,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const basicCC: any = new BasicCC({ - nodeId: 2, - data: serializedCC, - context: {} as any, - }); + const basicCC = CommandClass.parse( + serializedCC, + { sourceNodeId: 2 } as any, + ) as BasicCCReport; t.is(basicCC.constructor, BasicCC); }); @@ -133,7 +133,7 @@ test.only("getDefinedValueIDs() should include the target value for all endpoint test("BasicCCSet should expect no response", (t) => { const cc = new BasicCCSet({ nodeId: 2, - endpoint: 2, + endpointIndex: 2, targetValue: 7, }); t.false(cc.expectsCCResponse()); @@ -142,7 +142,7 @@ test("BasicCCSet should expect no response", (t) => { test("BasicCCSet => BasicCCReport = unexpected", (t) => { const ccRequest = new BasicCCSet({ nodeId: 2, - endpoint: 2, + endpointIndex: 2, targetValue: 7, }); const ccResponse = new BasicCCReport({ diff --git a/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts b/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts index 34694b45787f..d2efa97ee728 100644 --- a/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts @@ -1,10 +1,11 @@ import { BatteryCC, BatteryCCGet, - type BatteryCCReport, + BatteryCCReport, BatteryChargingStatus, BatteryCommand, BatteryReplacementStatus, + CommandClass, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; import test from "ava"; @@ -24,11 +25,11 @@ test("the Report command (v1) should be deserialized correctly: when the battery BatteryCommand.Report, // CC Command 55, // current value ]); - const batteryCC = new BatteryCC({ - nodeId: 7, - data: ccData, - context: {} as any, - }) as BatteryCCReport; + const batteryCC = CommandClass.parse( + ccData, + { sourceNodeId: 7 } as any, + ) as BatteryCCReport; + t.is(batteryCC.constructor, BatteryCCReport); t.is(batteryCC.level, 55); t.false(batteryCC.isLow); @@ -40,11 +41,11 @@ test("the Report command (v1) should be deserialized correctly: when the battery BatteryCommand.Report, // CC Command 0xff, // current value ]); - const batteryCC = new BatteryCC({ - nodeId: 7, - data: ccData, - context: {} as any, - }) as BatteryCCReport; + const batteryCC = CommandClass.parse( + ccData, + { sourceNodeId: 7 } as any, + ) as BatteryCCReport; + t.is(batteryCC.constructor, BatteryCCReport); t.is(batteryCC.level, 0); t.true(batteryCC.isLow); @@ -58,11 +59,11 @@ test("the Report command (v2) should be deserialized correctly: all flags set", 0b00_1111_00, 1, // disconnected ]); - const batteryCC = new BatteryCC({ - nodeId: 7, - data: ccData, - context: {} as any, - }) as BatteryCCReport; + const batteryCC = CommandClass.parse( + ccData, + { sourceNodeId: 7 } as any, + ) as BatteryCCReport; + t.is(batteryCC.constructor, BatteryCCReport); t.true(batteryCC.rechargeable); t.true(batteryCC.backup); @@ -79,11 +80,11 @@ test("the Report command (v2) should be deserialized correctly: charging status" 0b10_000000, // Maintaining 0, ]); - const batteryCC = new BatteryCC({ - nodeId: 7, - data: ccData, - context: {} as any, - }) as BatteryCCReport; + const batteryCC = CommandClass.parse( + ccData, + { sourceNodeId: 7 } as any, + ) as BatteryCCReport; + t.is(batteryCC.constructor, BatteryCCReport); t.is(batteryCC.chargingStatus, BatteryChargingStatus.Maintaining); }); @@ -96,11 +97,11 @@ test("the Report command (v2) should be deserialized correctly: recharge or repl 0b11, // Maintaining 0, ]); - const batteryCC = new BatteryCC({ - nodeId: 7, - data: ccData, - context: {} as any, - }) as BatteryCCReport; + const batteryCC = CommandClass.parse( + ccData, + { sourceNodeId: 7 } as any, + ) as BatteryCCReport; + t.is(batteryCC.constructor, BatteryCCReport); t.is(batteryCC.rechargeOrReplace, BatteryReplacementStatus.Now); }); @@ -110,12 +111,11 @@ test("deserializing an unsupported command should return an unspecified version CommandClasses.Battery, // CC 255, // not a valid command ]); - const basicCC: any = new BatteryCC({ - nodeId: 7, - data: serializedCC, - context: {} as any, - }); - t.is(basicCC.constructor, BatteryCC); + const batteryCC = CommandClass.parse( + serializedCC, + { sourceNodeId: 7 } as any, + ) as BatteryCCReport; + t.is(batteryCC.constructor, BatteryCC); }); // describe.skip(`interview()`, () => { diff --git a/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts b/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts index 523931edfa9e..08320b741ea4 100644 --- a/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts @@ -6,6 +6,7 @@ import { BinarySensorCCSupportedReport, BinarySensorCommand, BinarySensorType, + CommandClass, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; import test from "ava"; @@ -48,11 +49,11 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 0xff, // current value ]), ); - const cc = new BinarySensorCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as BinarySensorCCReport; + t.is(cc.constructor, BinarySensorCCReport); t.is(cc.value, true); }); @@ -65,11 +66,11 @@ test("the Report command (v2) should be deserialized correctly", (t) => { BinarySensorType.CO2, ]), ); - const cc = new BinarySensorCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as BinarySensorCCReport; + t.is(cc.constructor, BinarySensorCCReport); t.is(cc.value, false); t.is(cc.type, BinarySensorType.CO2); @@ -93,11 +94,11 @@ test("the SupportedReport command should be deserialized correctly", (t) => { 0b10, ]), ); - const cc = new BinarySensorCCSupportedReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as BinarySensorCCSupportedReport; + t.is(cc.constructor, BinarySensorCCSupportedReport); t.deepEqual(cc.supportedSensorTypes, [ BinarySensorType["General Purpose"], @@ -112,11 +113,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new BinarySensorCC({ - nodeId: 1, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 1 } as any, + ) as BinarySensorCC; t.is(cc.constructor, BinarySensorCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts index 5e5450d8f262..f0cc977f65ac 100644 --- a/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts @@ -4,6 +4,7 @@ import { BinarySwitchCCReport, BinarySwitchCCSet, BinarySwitchCommand, + CommandClass, } from "@zwave-js/cc"; import { CommandClasses, Duration } from "@zwave-js/core"; import { type GetSupportedCCVersion } from "@zwave-js/host"; @@ -79,11 +80,11 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 0xff, // current value ]), ); - const cc = new BinarySwitchCCReport({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as BinarySwitchCCReport; + t.is(cc.constructor, BinarySwitchCCReport); t.is(cc.currentValue, true); t.is(cc.targetValue, undefined); @@ -99,11 +100,11 @@ test("the Report command (v2) should be deserialized correctly", (t) => { 1, // duration ]), ); - const cc = new BinarySwitchCCReport({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as BinarySwitchCCReport; + t.is(cc.constructor, BinarySwitchCCReport); t.is(cc.currentValue, true); t.is(cc.targetValue, false); @@ -111,15 +112,14 @@ test("the Report command (v2) should be deserialized correctly", (t) => { t.is(cc.duration!.value, 1); }); -test("deserializing an unsupported command should return an unspecified version of BinarySwitchCC", (t) => { +test.only("deserializing an unsupported command should return an unspecified version of BinarySwitchCC", (t) => { const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new BinarySwitchCC({ - nodeId: 2, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 2 } as any, + ) as BinarySwitchCC; t.is(cc.constructor, BinarySwitchCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts b/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts index 64cefd9110ef..027a74774a00 100644 --- a/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts @@ -37,11 +37,10 @@ test("serialization and deserialization should be compatible", (t) => { t.is(crc16.encapsulated, basicCCSet); const serialized = crc16.serialize({} as any); - const deserialized = CommandClass.from({ - nodeId: basicCCSet.nodeId as number, - data: serialized, - context: {} as any, - }); + const deserialized = CommandClass.parse( + serialized, + { sourceNodeId: basicCCSet.nodeId as number } as any, + ); t.is(deserialized.nodeId, basicCCSet.nodeId); const deserializedPayload = (deserialized as CRC16CCCommandEncapsulation) .encapsulated as BasicCCSet; @@ -61,10 +60,9 @@ test("deserializing a CC with a wrong checksum should result in an invalid CC", const serialized = crc16.serialize({} as any); serialized[serialized.length - 1] ^= 0xff; - const decoded = CommandClass.from({ - nodeId: basicCCSet.nodeId as number, - data: serialized, - context: {} as any, - }); - t.true(decoded instanceof InvalidCC); + const deserialized = CommandClass.parse( + serialized, + { sourceNodeId: basicCCSet.nodeId as number } as any, + ); + t.true(deserialized instanceof InvalidCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts b/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts index 0aa07df4f406..3bdb279111b4 100644 --- a/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts @@ -8,6 +8,7 @@ import { CentralSceneCCSupportedReport, CentralSceneCommand, CentralSceneKeys, + CommandClass, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; import test from "ava"; @@ -68,11 +69,11 @@ test("the ConfigurationReport command should be deserialized correctly", (t) => 0b1000_0000, ]), ); - const cc = new CentralSceneCCConfigurationReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as CentralSceneCCConfigurationReport; + t.is(cc.constructor, CentralSceneCCConfigurationReport); t.is(cc.slowRefresh, true); }); @@ -101,11 +102,11 @@ test("the SupportedReport command should be deserialized correctly", (t) => { 0, ]), ); - const cc = new CentralSceneCCSupportedReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as CentralSceneCCSupportedReport; + t.is(cc.constructor, CentralSceneCCSupportedReport); t.is(cc.sceneCount, 2); t.true(cc.supportsSlowRefresh); @@ -124,11 +125,11 @@ test("the Notification command should be deserialized correctly", (t) => { 8, // scene number ]), ); - const cc = new CentralSceneCCNotification({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as CentralSceneCCNotification; + t.is(cc.constructor, CentralSceneCCNotification); t.is(cc.sequenceNumber, 7); // slow refresh is only evaluated if the attribute is KeyHeldDown @@ -146,11 +147,11 @@ test("the Notification command should be deserialized correctly (KeyHeldDown)", 8, // scene number ]), ); - const cc = new CentralSceneCCNotification({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as CentralSceneCCNotification; + t.is(cc.constructor, CentralSceneCCNotification); t.is(cc.sequenceNumber, 7); t.true(cc.slowRefresh); @@ -162,11 +163,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new CentralSceneCC({ - nodeId: 1, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 1 } as any, + ) as CentralSceneCC; t.is(cc.constructor, CentralSceneCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts index 957a23f0fd1e..da917686d044 100644 --- a/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts @@ -9,6 +9,7 @@ import { ColorSwitchCCSupportedGet, ColorSwitchCCSupportedReport, ColorSwitchCommand, + CommandClass, } from "@zwave-js/cc"; import { CommandClasses, @@ -48,11 +49,11 @@ test("the SupportedReport command should deserialize correctly", (t) => { 0b0000_0001, ]), ); - const cc = new ColorSwitchCCSupportedReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as ColorSwitchCCSupportedReport; + t.is(cc.constructor, ColorSwitchCCSupportedReport); t.deepEqual(cc.supportedColorComponents, [ ColorComponent["Warm White"], @@ -91,11 +92,11 @@ test("the Report command should deserialize correctly (version 1)", (t) => { 0b1111_1111, // value: 255 ]), ); - const cc = new ColorSwitchCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as ColorSwitchCCReport; + t.is(cc.constructor, ColorSwitchCCReport); t.is(cc.colorComponent, ColorComponent.Red); t.is(cc.currentValue, 255); @@ -113,11 +114,11 @@ test("the Report command should deserialize correctly (version 3)", (t) => { 0b0000_0001, // duration: 1 ]), ); - const cc = new ColorSwitchCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as ColorSwitchCCReport; + t.is(cc.constructor, ColorSwitchCCReport); t.is(cc.colorComponent, ColorComponent.Red); t.is(cc.currentValue, 128); diff --git a/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts b/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts index 83a03979d623..81ed93adca18 100644 --- a/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts @@ -1,4 +1,4 @@ -import { CentralSceneCommand, CentralSceneKeys } from "@zwave-js/cc"; +import { CentralSceneKeys } from "@zwave-js/cc"; import { BasicCCSet } from "@zwave-js/cc/BasicCC"; import { CentralSceneCCNotification } from "@zwave-js/cc/CentralSceneCC"; import { CommandClasses } from "@zwave-js/core"; @@ -93,14 +93,9 @@ test(`persistValues() should not store values marked as "events" (non-stateful)` const cc = new CentralSceneCCNotification({ nodeId: node2.id, - data: Buffer.from([ - CommandClasses["Central Scene"], - CentralSceneCommand.Notification, - 1, // seq number - CentralSceneKeys.KeyPressed, - 1, // scene number - ]), - context: {} as any, + sequenceNumber: 1, + sceneNumber: 1, + keyAttribute: CentralSceneKeys.KeyPressed, }); // Central Scene should use the value notification event instead of added/updated diff --git a/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts b/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts index 034bf949489f..2da463646b1a 100644 --- a/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts @@ -42,13 +42,12 @@ test(`creating and serializing should work for unspecified commands`, (t) => { ); }); -test("from() returns an un-specialized instance when receiving a non-implemented CC", (t) => { +test("parse() returns an un-specialized instance when receiving a non-implemented CC", (t) => { // This is a Node Provisioning CC. Change it when that CC is implemented - const cc = CommandClass.from({ - data: Buffer.from("78030100", "hex"), - nodeId: 5, - context: {} as any, - }); + const cc = CommandClass.parse( + Buffer.from("78030100", "hex"), + { sourceNodeId: 5 } as any, + ); t.is(cc.constructor, CommandClass); t.is(cc.nodeId, 5); t.is(cc.ccId, 0x78); @@ -56,14 +55,13 @@ test("from() returns an un-specialized instance when receiving a non-implemented t.deepEqual(cc.payload, Buffer.from([0x01, 0x00])); }); -test("from() does not throw when the CC is implemented", (t) => { +test("parse() does not throw when the CC is implemented", (t) => { t.notThrows(() => - CommandClass.from({ - // CRC-16 with BasicCC - data: Buffer.from("560120024d26", "hex"), - nodeId: 5, - context: {} as any, - }) + // CRC-16 with BasicCC + CommandClass.parse( + Buffer.from("560120024d26", "hex"), + { sourceNodeId: 5 } as any, + ) ); }); diff --git a/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts b/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts index ac5bf54758d2..3167154c3c41 100644 --- a/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, DoorLockCCCapabilitiesGet, DoorLockCCCapabilitiesReport, DoorLockCCConfigurationGet, @@ -74,11 +75,11 @@ test("the OperationReport command (v1-v3) should be deserialized correctly", (t) 20, // timeout seconds ]), ); - const cc = new DoorLockCCOperationReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as DoorLockCCOperationReport; + t.is(cc.constructor, DoorLockCCOperationReport); t.is(cc.currentMode, DoorLockMode.InsideUnsecuredWithTimeout); t.deepEqual(cc.outsideHandlesCanOpenDoor, [false, false, false, true]); @@ -104,11 +105,11 @@ test("the OperationReport command (v4) should be deserialized correctly", (t) => 0x01, // 1 second left ]), ); - const cc = new DoorLockCCOperationReport({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as DoorLockCCOperationReport; + t.is(cc.constructor, DoorLockCCOperationReport); cc.persistValues(host); t.is(cc.currentMode, DoorLockMode.OutsideUnsecured); @@ -149,11 +150,11 @@ test("the ConfigurationReport command (v1-v3) should be deserialized correctly", 20, // timeout seconds ]), ); - const cc = new DoorLockCCConfigurationReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as DoorLockCCConfigurationReport; + t.is(cc.constructor, DoorLockCCConfigurationReport); t.is(cc.operationType, DoorLockOperationType.Timed); t.deepEqual(cc.outsideHandlesCanOpenDoorConfiguration, [ @@ -185,11 +186,11 @@ test("the ConfigurationReport command must ignore invalid timeouts (constant)", 20, // timeout seconds ]), ); - const cc = new DoorLockCCConfigurationReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as DoorLockCCConfigurationReport; + t.is(cc.constructor, DoorLockCCConfigurationReport); t.is(cc.lockTimeoutConfiguration, undefined); }); @@ -204,11 +205,11 @@ test("the ConfigurationReport command must ignore invalid timeouts (invalid minu 20, // timeout seconds ]), ); - const cc = new DoorLockCCConfigurationReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as DoorLockCCConfigurationReport; + t.is(cc.constructor, DoorLockCCConfigurationReport); t.is(cc.lockTimeoutConfiguration, undefined); }); @@ -223,11 +224,11 @@ test("the ConfigurationReport command must ignore invalid timeouts (invalid seco 0xff, // timeout seconds ]), ); - const cc = new DoorLockCCConfigurationReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as DoorLockCCConfigurationReport; + t.is(cc.constructor, DoorLockCCConfigurationReport); t.is(cc.lockTimeoutConfiguration, undefined); }); @@ -248,11 +249,11 @@ test("the ConfigurationReport command (v4) should be deserialized correctly", (t 0b01, // flags ]), ); - const cc = new DoorLockCCConfigurationReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as DoorLockCCConfigurationReport; + t.is(cc.constructor, DoorLockCCConfigurationReport); t.is(cc.autoRelockTime, 0xff01); t.is(cc.holdAndReleaseTime, 0x0203); @@ -314,11 +315,11 @@ test("the CapabilitiesReport command should be deserialized correctly", (t) => { 0b1010, // feature flags ]), ); - const cc = new DoorLockCCCapabilitiesReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as DoorLockCCCapabilitiesReport; + t.is(cc.constructor, DoorLockCCCapabilitiesReport); t.deepEqual(cc.supportedOperationTypes, [ DoorLockOperationType.Constant, diff --git a/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts b/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts index c8e234abb8c4..f6a783a63637 100644 --- a/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, DoorLockLoggingCCRecordGet, DoorLockLoggingCCRecordReport, DoorLockLoggingCCRecordsSupportedGet, @@ -37,11 +38,11 @@ test("the RecordsCountReport command should be deserialized correctly", (t) => { 0x14, // max records supported (20) ]), ); - const cc = new DoorLockLoggingCCRecordsSupportedReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as DoorLockLoggingCCRecordsSupportedReport; + t.is(cc.constructor, DoorLockLoggingCCRecordsSupportedReport); t.is(cc.recordsCount, 20); }); @@ -79,11 +80,11 @@ test("the RecordReport command should be deserialized correctly", (t) => { ]), ); - const cc = new DoorLockLoggingCCRecordReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as DoorLockLoggingCCRecordReport; + t.is(cc.constructor, DoorLockLoggingCCRecordReport); t.is(cc.recordNumber, 7); diff --git a/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts b/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts index 168677275714..6c2de3081d77 100644 --- a/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, EntryControlCCConfigurationGet, EntryControlCCConfigurationReport, EntryControlCCConfigurationSet, @@ -42,11 +43,11 @@ test("the Notification command should deserialize correctly", (t) => { ]), ); - const cc = new EntryControlCCNotification({ - nodeId: 1, + const cc = CommandClass.parse( data, - context: {} as any, - }); + { sourceNodeId: 1 } as any, + ) as EntryControlCCNotification; + t.is(cc.constructor, EntryControlCCNotification); t.deepEqual(cc.sequenceNumber, 1); t.deepEqual(cc.dataType, EntryControlDataTypes.ASCII); @@ -91,11 +92,11 @@ test("the ConfigurationReport command should be deserialize correctly", (t) => { ]), ); - const cc = new EntryControlCCConfigurationReport({ - nodeId: 1, + const cc = CommandClass.parse( data, - context: {} as any, - }); + { sourceNodeId: 1 } as any, + ) as EntryControlCCConfigurationReport; + t.is(cc.constructor, EntryControlCCConfigurationReport); t.deepEqual(cc.keyCacheSize, 1); t.deepEqual(cc.keyCacheTimeout, 2); @@ -131,11 +132,11 @@ test("the EventSupportedReport command should be deserialize correctly", (t) => ]), ); - const cc = new EntryControlCCEventSupportedReport({ - nodeId: 1, + const cc = CommandClass.parse( data, - context: {} as any, - }); + { sourceNodeId: 1 } as any, + ) as EntryControlCCEventSupportedReport; + t.is(cc.constructor, EntryControlCCEventSupportedReport); t.deepEqual(cc.supportedDataTypes, [EntryControlDataTypes.ASCII]); t.deepEqual(cc.supportedEventTypes, [ @@ -169,11 +170,11 @@ test("the KeySupportedReport command should be deserialize correctly", (t) => { ]), ); - const cc = new EntryControlCCKeySupportedReport({ - nodeId: 1, + const cc = CommandClass.parse( data, - context: {} as any, - }); + { sourceNodeId: 1 } as any, + ) as EntryControlCCKeySupportedReport; + t.is(cc.constructor, EntryControlCCKeySupportedReport); t.deepEqual(cc.supportedKeys, [1, 3, 4, 6]); }); diff --git a/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts b/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts index 7d21f7330e97..bb8fe9bc9488 100644 --- a/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts @@ -47,14 +47,13 @@ test("the Report command should be deserialized correctly", (t) => { 0x00, // Tilt ]), ); - const cc = CommandClass.from({ - nodeId: 2, - data: ccData, - context: {} as any, - }); - t.true(cc instanceof FibaroVenetianBlindCCReport); - t.is((cc as FibaroVenetianBlindCCReport).position, 0); - t.is((cc as FibaroVenetianBlindCCReport).tilt, 0); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as FibaroVenetianBlindCCReport; + t.is(cc.constructor, FibaroVenetianBlindCCReport); + t.is(cc.position, 0); + t.is(cc.tilt, 0); }); test("FibaroVenetianBlindCCSet should expect no response", (t) => { @@ -77,9 +76,8 @@ test("FibaroVenetianBlindCCSet => FibaroVenetianBlindCCReport = unexpected", (t) nodeId: 2, tilt: 7, }); - const ccResponse = new FibaroVenetianBlindCCReport({ - nodeId: 2, - data: buildCCBuffer( + const ccResponse = CommandClass.parse( + buildCCBuffer( Buffer.from([ FibaroVenetianBlindCCCommand.Report, 0x03, // with Tilt and Position @@ -87,8 +85,8 @@ test("FibaroVenetianBlindCCSet => FibaroVenetianBlindCCReport = unexpected", (t) 0x07, // Tilt ]), ), - context: {} as any, - }); + { sourceNodeId: 2 } as any, + ) as FibaroVenetianBlindCCReport; t.false(ccRequest.isExpectedCCResponse(ccResponse)); }); @@ -97,9 +95,8 @@ test("FibaroVenetianBlindCCGet => FibaroVenetianBlindCCReport = expected", (t) = const ccRequest = new FibaroVenetianBlindCCGet({ nodeId: 2, }); - const ccResponse = new FibaroVenetianBlindCCReport({ - nodeId: 2, - data: buildCCBuffer( + const ccResponse = CommandClass.parse( + buildCCBuffer( Buffer.from([ FibaroVenetianBlindCCCommand.Report, 0x03, // with Tilt and Position @@ -107,8 +104,8 @@ test("FibaroVenetianBlindCCGet => FibaroVenetianBlindCCReport = expected", (t) = 0x07, // Tilt ]), ), - context: {} as any, - }); + { sourceNodeId: 2 } as any, + ) as FibaroVenetianBlindCCReport; t.true(ccRequest.isExpectedCCResponse(ccResponse)); }); diff --git a/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts b/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts index 158b1926bf2f..ab4b15c30b97 100644 --- a/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, HumidityControlOperatingState, HumidityControlOperatingStateCCGet, HumidityControlOperatingStateCCReport, @@ -35,11 +36,11 @@ test("the Report command should be deserialized correctly", (t) => { HumidityControlOperatingState.Humidifying, // state ]), ); - const cc = new HumidityControlOperatingStateCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as HumidityControlOperatingStateCCReport; + t.is(cc.constructor, HumidityControlOperatingStateCCReport); t.is(cc.state, HumidityControlOperatingState.Humidifying); }); diff --git a/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts b/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts index 05a6cd7f2f03..bd6e42323bdb 100644 --- a/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts @@ -100,11 +100,11 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 55, // value ]), ); - const cc = new IndicatorCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as IndicatorCCReport; + t.is(cc.constructor, IndicatorCCReport); t.is(cc.indicator0Value, 55); t.is(cc.values, undefined); @@ -124,11 +124,11 @@ test("the Report command (v2) should be deserialized correctly", (t) => { 1, // value ]), ); - const cc = new IndicatorCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as IndicatorCCReport; + t.is(cc.constructor, IndicatorCCReport); // Boolean indicators are only interpreted during persistValues cc.persistValues(host); @@ -151,11 +151,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new IndicatorCC({ - nodeId: 1, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 1 } as any, + ) as IndicatorCC; t.is(cc.constructor, IndicatorCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts b/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts index 6fd678841444..434a6309e9bd 100644 --- a/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, LanguageCC, LanguageCCGet, LanguageCCReport, @@ -75,11 +76,11 @@ test("the Report command should be deserialized correctly (w/o country code)", ( 0x75, ]), ); - const cc = new LanguageCCReport({ - nodeId: 4, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 4 } as any, + ) as LanguageCCReport; + t.is(cc.constructor, LanguageCCReport); t.is(cc.language, "deu"); t.is(cc.country, undefined); @@ -98,11 +99,11 @@ test("the Report command should be deserialized correctly (w/ country code)", (t 0x45, ]), ); - const cc = new LanguageCCReport({ - nodeId: 4, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 4 } as any, + ) as LanguageCCReport; + t.is(cc.constructor, LanguageCCReport); t.is(cc.language, "deu"); t.is(cc.country, "DE"); @@ -112,11 +113,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new LanguageCC({ - nodeId: 4, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 4 } as any, + ) as LanguageCC; t.is(cc.constructor, LanguageCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts b/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts index 66e1ba7dac7e..111562efa31e 100644 --- a/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, ManufacturerSpecificCCGet, ManufacturerSpecificCCReport, ManufacturerSpecificCommand, @@ -37,11 +38,11 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 0x06, ]), ); - const cc = new ManufacturerSpecificCCReport({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as ManufacturerSpecificCCReport; + t.is(cc.constructor, ManufacturerSpecificCCReport); t.is(cc.manufacturerId, 0x0102); t.is(cc.productType, 0x0304); diff --git a/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts b/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts index a335be76bad0..155a3dd9e0ab 100644 --- a/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, MeterCC, MeterCCGet, MeterCCReport, @@ -146,11 +147,11 @@ test("the Report command (V1) should be deserialized correctly", (t) => { 55, // value ]), ); - const cc = new MeterCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as MeterCCReport; + t.is(cc.constructor, MeterCCReport); t.is(cc.type, 3); t.is(cc.scale, 2); @@ -171,11 +172,11 @@ test("the Report command (V2) should be deserialized correctly (no time delta)", 0, ]), ); - const cc = new MeterCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as MeterCCReport; + t.is(cc.constructor, MeterCCReport); t.is(cc.type, 3); t.is(cc.scale, 2); @@ -197,11 +198,11 @@ test("the Report command (V2) should be deserialized correctly (with time delta) 54, // previous value ]), ); - const cc = new MeterCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as MeterCCReport; + t.is(cc.constructor, MeterCCReport); t.is(cc.type, 3); t.is(cc.scale, 2); @@ -223,11 +224,11 @@ test("the Report command (V3) should be deserialized correctly", (t) => { 54, // previous value ]), ); - const cc = new MeterCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as MeterCCReport; + t.is(cc.constructor, MeterCCReport); t.is(cc.scale, 6); }); @@ -245,11 +246,11 @@ test("the Report command (V4) should be deserialized correctly", (t) => { 0b01, // Scale2 ]), ); - const cc = new MeterCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as MeterCCReport; + t.is(cc.constructor, MeterCCReport); t.is(cc.scale, 8); }); @@ -268,11 +269,11 @@ test("the Report command should validate that a known meter type is given", (t) ]), ); - const report = new MeterCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const report = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as MeterCCReport; + t.is(cc.constructor, MeterCCReport); // Meter type 31 (does not exist) assertZWaveError(t, () => report.persistValues(host), { @@ -294,11 +295,11 @@ test("the Report command should validate that a known meter scale is given", (t) ]), ); - const report = new MeterCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const report = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as MeterCCReport; + t.is(cc.constructor, MeterCCReport); // Meter type 4, Scale 8 (does not exist) assertZWaveError(t, () => report.persistValues(host), { @@ -327,11 +328,11 @@ test("the SupportedReport command (V2/V3) should be deserialized correctly", (t) 0b01101110, // supported scales ]), ); - const cc = new MeterCCSupportedReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as MeterCCSupportedReport; + t.is(cc.constructor, MeterCCSupportedReport); t.is(cc.type, 21); t.true(cc.supportsReset); @@ -350,11 +351,11 @@ test("the SupportedReport command (V4/V5) should be deserialized correctly", (t) 1, ]), ); - const cc = new MeterCCSupportedReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as MeterCCSupportedReport; + t.is(cc.constructor, MeterCCSupportedReport); t.is(cc.type, 21); t.true(cc.supportsReset); @@ -388,11 +389,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new MeterCC({ - nodeId: 1, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 1 } as any, + ) as MeterCC; t.is(cc.constructor, MeterCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts index 12db92f59c6f..bef3e1dfb1c7 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, MultiChannelAssociationCCGet, MultiChannelAssociationCCRemove, MultiChannelAssociationCCReport, @@ -38,11 +39,11 @@ test("the SupportedGroupingsReport command should be deserialized correctly", (t 7, // # of groups ]), ); - const cc = new MultiChannelAssociationCCSupportedGroupingsReport({ - nodeId: 4, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 4 } as any, + ) as MultiChannelAssociationCCSupportedGroupingsReport; + t.is(cc.constructor, MultiChannelAssociationCCSupportedGroupingsReport); t.is(cc.groupCount, 7); }); @@ -160,11 +161,11 @@ test("the Report command should be deserialized correctly (node IDs only)", (t) 5, ]), ); - const cc = new MultiChannelAssociationCCReport({ - nodeId: 4, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 4 } as any, + ) as MultiChannelAssociationCCReport; + t.is(cc.constructor, MultiChannelAssociationCCReport); t.is(cc.groupId, 5); t.is(cc.maxNodes, 9); @@ -189,11 +190,11 @@ test("the Report command should be deserialized correctly (endpoint addresses on 0b11010111, ]), ); - const cc = new MultiChannelAssociationCCReport({ - nodeId: 4, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 4 } as any, + ) as MultiChannelAssociationCCReport; + t.is(cc.constructor, MultiChannelAssociationCCReport); t.deepEqual(cc.nodeIds, []); t.deepEqual(cc.endpoints, [ @@ -227,11 +228,11 @@ test("the Report command should be deserialized correctly (both options)", (t) = 0b11010111, ]), ); - const cc = new MultiChannelAssociationCCReport({ - nodeId: 4, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 4 } as any, + ) as MultiChannelAssociationCCReport; + t.is(cc.constructor, MultiChannelAssociationCCReport); t.deepEqual(cc.nodeIds, [1, 5, 9]); t.deepEqual(cc.endpoints, [ diff --git a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts index 78053cc8e033..0b07229483c9 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts @@ -1,4 +1,4 @@ -import type { CommandClass } from "@zwave-js/cc"; +import { CommandClass } from "@zwave-js/cc"; import { BasicCCGet, BasicCCReport, @@ -150,11 +150,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new MultiChannelCC({ - nodeId: 1, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 1 } as any, + ) as MultiChannelCC; t.is(cc.constructor, MultiChannelCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts index 2d5f30b129dd..753e22153ba5 100644 --- a/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, MultilevelSwitchCC, MultilevelSwitchCCGet, MultilevelSwitchCCReport, @@ -81,11 +82,11 @@ test("the Report command (V1) should be deserialized correctly", (t) => { 55, // current value ]), ); - const cc = new MultilevelSwitchCCReport({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as MultilevelSwitchCCReport; + t.is(cc.constructor, MultilevelSwitchCCReport); t.is(cc.currentValue, 55); t.is(cc.targetValue, undefined); @@ -101,11 +102,11 @@ test("the Report command (v4) should be deserialized correctly", (t) => { 1, // duration ]), ); - const cc = new MultilevelSwitchCCReport({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as MultilevelSwitchCCReport; + t.is(cc.constructor, MultilevelSwitchCCReport); t.is(cc.currentValue, 55); t.is(cc.targetValue, 66); @@ -166,11 +167,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new MultilevelSwitchCC({ - nodeId: 2, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 2 } as any, + ) as MultilevelSwitchCC; t.is(cc.constructor, MultilevelSwitchCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts b/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts index d847a7b75013..54222320b630 100644 --- a/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, Powerlevel, PowerlevelCC, PowerlevelCCGet, @@ -83,11 +84,11 @@ test("the Report command should be deserialized correctly (NormalPower)", (t) => 50, // timeout (ignored because NormalPower) ]), ); - const cc = new PowerlevelCCReport({ - nodeId: 5, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 5 } as any, + ) as PowerlevelCCReport; + t.is(cc.constructor, PowerlevelCCReport); t.is(cc.powerlevel, Powerlevel["Normal Power"]); t.is(cc.timeout, undefined); // timeout does not apply to NormalPower @@ -101,11 +102,11 @@ test("the Report command should be deserialized correctly (custom power)", (t) = 50, // timeout (ignored because NormalPower) ]), ); - const cc = new PowerlevelCCReport({ - nodeId: 5, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 5 } as any, + ) as PowerlevelCCReport; + t.is(cc.constructor, PowerlevelCCReport); t.is(cc.powerlevel, Powerlevel["-3 dBm"]); t.is(cc.timeout, 50); // timeout does not apply to NormalPower @@ -115,10 +116,9 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new PowerlevelCC({ - nodeId: 1, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 1 } as any, + ) as PowerlevelCC; t.is(cc.constructor, PowerlevelCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts index 4520223956af..d9eddc9e718b 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, SceneActivationCC, SceneActivationCCSet, SceneActivationCommand, @@ -54,11 +55,11 @@ test("the Set command should be deserialized correctly", (t) => { 0x00, // 0 seconds ]), ); - const cc = new SceneActivationCCSet({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as SceneActivationCCSet; + t.is(cc.constructor, SceneActivationCCSet); t.is(cc.sceneId, 15); t.deepEqual(cc.dimmingDuration, new Duration(0, "seconds")); @@ -68,11 +69,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new SceneActivationCC({ - nodeId: 2, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 2 } as any, + ) as SceneActivationCC; t.is(cc.constructor, SceneActivationCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts index 7270aef3ee8a..ed40a7b1cb21 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, SceneActuatorConfigurationCC, SceneActuatorConfigurationCCGet, SceneActuatorConfigurationCCReport, @@ -78,11 +79,11 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 0x05, // dimmingDuration ]), ); - const cc = new SceneActuatorConfigurationCCReport({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as SceneActuatorConfigurationCCReport; + t.is(cc.constructor, SceneActuatorConfigurationCCReport); t.is(cc.sceneId, 55); t.is(cc.level, 0x50); @@ -93,10 +94,9 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new SceneActuatorConfigurationCC({ - nodeId: 2, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 2 } as any, + ) as SceneActuatorConfigurationCC; t.is(cc.constructor, SceneActuatorConfigurationCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts index ff76ea6285ec..64966795cb65 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, SceneControllerConfigurationCC, SceneControllerConfigurationCCGet, SceneControllerConfigurationCCReport, @@ -76,11 +77,11 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 0x05, // dimming duration ]), ); - const cc = new SceneControllerConfigurationCCReport({ - nodeId: 2, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 2 } as any, + ) as SceneControllerConfigurationCCReport; + t.is(cc.constructor, SceneControllerConfigurationCCReport); t.is(cc.groupId, 3); t.is(cc.sceneId, 240); @@ -91,10 +92,9 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new SceneControllerConfigurationCC({ - nodeId: 1, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 1 } as any, + ) as SceneControllerConfigurationCC; t.is(cc.constructor, SceneControllerConfigurationCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts b/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts index 72cc8c72bef7..ea0b4e98dac1 100644 --- a/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, ThermostatFanMode, ThermostatFanModeCCGet, ThermostatFanModeCCReport, @@ -64,11 +65,11 @@ test("the Report command should be deserialized correctly", (t) => { 0b1000_0010, // Off bit set to 1 and Auto high mode ]), ); - const cc = new ThermostatFanModeCCReport({ - nodeId: 5, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 5 } as any, + ) as ThermostatFanModeCCReport; + t.is(cc.constructor, ThermostatFanModeCCReport); t.is(cc.mode, ThermostatFanMode["Auto high"]); t.is(cc.off, true); diff --git a/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts b/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts index 03ff89fe8d98..1766069a644c 100644 --- a/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, ThermostatFanState, ThermostatFanStateCC, ThermostatFanStateCCGet, @@ -34,11 +35,11 @@ test("the Report command (v1 - v2) should be deserialized correctly", (t) => { ThermostatFanState["Idle / off"], // state ]), ); - const cc = new ThermostatFanStateCCReport({ - nodeId: 1, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 1 } as any, + ) as ThermostatFanStateCCReport; + t.is(cc.constructor, ThermostatFanStateCCReport); t.is(cc.state, ThermostatFanState["Idle / off"]); }); @@ -47,11 +48,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new ThermostatFanStateCC({ - nodeId: 1, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 1 } as any, + ) as ThermostatFanStateCC; t.is(cc.constructor, ThermostatFanStateCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts b/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts index 8635a5ec304e..d9f24ae44afa 100644 --- a/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts @@ -1,4 +1,5 @@ import { + CommandClass, TimeCC, TimeCCDateGet, TimeCCDateReport, @@ -37,11 +38,11 @@ test("the TimeReport command should be deserialized correctly", (t) => { 59, ]), ); - const cc = new TimeCCTimeReport({ - nodeId: 8, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 8 } as any, + ) as TimeCCTimeReport; + t.is(cc.constructor, TimeCCTimeReport); t.is(cc.hour, 14); t.is(cc.minute, 23); @@ -68,11 +69,11 @@ test("the DateReport command should be deserialized correctly", (t) => { 17, ]), ); - const cc = new TimeCCDateReport({ - nodeId: 8, - data: ccData, - context: {} as any, - }); + const cc = CommandClass.parse( + ccData, + { sourceNodeId: 8 } as any, + ) as TimeCCDateReport; + t.is(cc.constructor, TimeCCDateReport); t.is(cc.year, 1989); t.is(cc.month, 10); @@ -83,11 +84,10 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new TimeCC({ - nodeId: 8, - data: serializedCC, - context: {} as any, - }); + const cc = CommandClass.parse( + serializedCC, + { sourceNodeId: 8 } as any, + ) as TimeCC; t.is(cc.constructor, TimeCC); });