From 92589dcb85783e7f0e0a67fb8e655bb0ddc8f129 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 8 Jul 2024 13:41:45 +0200 Subject: [PATCH] fix: do not expose Basic CC current value if Set is mapped to another CC --- packages/cc/src/cc/BasicCC.ts | 3 +- .../basicCCSupportWhenForbidden.test.ts | 58 +++++++++++++++++++ .../mapBasicSetBinarySensor/deviceConfig.json | 19 ++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 packages/zwave-js/src/lib/test/compat/fixtures/mapBasicSetBinarySensor/deviceConfig.json diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index 36800873e9bb..0507077d3a67 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -333,7 +333,8 @@ remaining duration: ${basicResponse.duration?.toString() ?? "undefined"}`; ret.push(BasicCCValues.compatEvent.endpoint(endpoint.index)); } else if ( !endpoint.supportsCC(CommandClasses.Basic) && ( - endpoint.controlsCC(CommandClasses.Basic) + (endpoint.controlsCC(CommandClasses.Basic) + && compat?.mapBasicSet !== "Binary Sensor") || compat?.mapBasicReport === false || compat?.mapBasicSet === "report" ) diff --git a/packages/zwave-js/src/lib/test/compat/basicCCSupportWhenForbidden.test.ts b/packages/zwave-js/src/lib/test/compat/basicCCSupportWhenForbidden.test.ts index 55fe9ef4043b..3f8b8d23d4e1 100644 --- a/packages/zwave-js/src/lib/test/compat/basicCCSupportWhenForbidden.test.ts +++ b/packages/zwave-js/src/lib/test/compat/basicCCSupportWhenForbidden.test.ts @@ -1,5 +1,6 @@ import { BasicCCValues } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; +import path from "node:path"; import { integrationTest } from "../integrationTestSuite"; integrationTest( @@ -44,3 +45,60 @@ integrationTest( }, }, ); + +integrationTest( + "On devices that MUST not support Basic CC, and map Basic Set to a different CC, NO Basic CC values should be exposed", + { + // debug: true, + + nodeCapabilities: { + manufacturerId: 0xdead, + productType: 0xbeef, + productId: 0xcafe, + + // Routing Multilevel Sensor, MUST not support Basic CC + genericDeviceClass: 0x21, + specificDeviceClass: 0x01, + commandClasses: [ + CommandClasses["Manufacturer Specific"], + CommandClasses.Version, + // But it reports support if asked + CommandClasses.Basic, + ], + }, + + additionalDriverOptions: { + storage: { + deviceConfigPriorityDir: path.join( + __dirname, + "fixtures/mapBasicSetBinarySensor", + ), + }, + }, + + async testBody(t, driver, node, mockController, mockNode) { + const valueIDs = node.getDefinedValueIDs(); + t.false( + valueIDs.some((v) => BasicCCValues.currentValue.is(v)), + "Found Basic CC currentValue although it shouldn't be exposed", + ); + t.false( + valueIDs.some((v) => BasicCCValues.targetValue.is(v)), + "Found Basic CC targetValue although it shouldn't be exposed", + ); + t.false( + valueIDs.some((v) => BasicCCValues.duration.is(v)), + "Found Basic CC duration although it shouldn't be exposed", + ); + t.false( + valueIDs.some((v) => BasicCCValues.restorePrevious.is(v)), + "Found Basic CC restorePrevious although it shouldn't be exposed", + ); + + t.false( + valueIDs.some((v) => BasicCCValues.compatEvent.is(v)), + "Found Basic CC compatEvent although it shouldn't be exposed", + ); + }, + }, +); diff --git a/packages/zwave-js/src/lib/test/compat/fixtures/mapBasicSetBinarySensor/deviceConfig.json b/packages/zwave-js/src/lib/test/compat/fixtures/mapBasicSetBinarySensor/deviceConfig.json new file mode 100644 index 000000000000..e8fc17b79d6c --- /dev/null +++ b/packages/zwave-js/src/lib/test/compat/fixtures/mapBasicSetBinarySensor/deviceConfig.json @@ -0,0 +1,19 @@ +{ + "manufacturer": "Test Manufacturer", + "manufacturerId": "0xdead", + "label": "Test Device", + "description": "With Basic Event", + "devices": [ + { + "productType": "0xbeef", + "productId": "0xcafe" + } + ], + "firmwareVersion": { + "min": "0.0", + "max": "255.255" + }, + "compat": { + "mapBasicSet": "Binary Sensor" + } +}