From 02717978f30413469302436f9f78d5c18f7fa8dd Mon Sep 17 00:00:00 2001 From: sofie Date: Thu, 18 Aug 2022 21:00:33 +0200 Subject: [PATCH 1/2] added doorbell5 aka smarthome wb008 --- package.json | 5 ++++- src/controller.coffee | 2 +- src/protocols/doorbell5.coffee | 34 ++++++++++++++++++++++++++++++++++ test/lib-controller.coffee | 10 ++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/protocols/doorbell5.coffee diff --git a/package.json b/package.json index be9565b..e8d17a2 100644 --- a/package.json +++ b/package.json @@ -31,12 +31,15 @@ }, "devDependencies": { "coffee-script": "^1.12.2", - "gulp": "~3.9.1", + "gulp": "^3.9.1", "gulp-coffee": "~2.3.3", "gulp-coffee-istanbul": "^0.9.1", "gulp-coffeelint": "^0.6.0", "gulp-mocha": "^3.0.1", "gulp-plumber": "~1.1.0", "gulp-watch": "~4.3.11" + }, + "dependencies": { + "traceur": "0.0.111" } } diff --git a/src/controller.coffee b/src/controller.coffee index 5b5f817..bb3c317 100644 --- a/src/controller.coffee +++ b/src/controller.coffee @@ -15,7 +15,7 @@ protocols = [ 'generic', 'generic2' 'alarm1', 'alarm2', 'alarm3' 'led1', 'led2', 'led3', 'led4' - 'doorbell1', 'doorbell2', 'doorbell3', + 'doorbell1', 'doorbell2', 'doorbell3', 'doorbell5' 'awning1', 'awning2' 'shutter1', 'shutter3', 'shutter4', 'shutter5' 'rawswitch', 'rawshutter' diff --git a/src/protocols/doorbell5.coffee b/src/protocols/doorbell5.coffee new file mode 100644 index 0000000..967fe20 --- /dev/null +++ b/src/protocols/doorbell5.coffee @@ -0,0 +1,34 @@ +module.exports = (helper) -> + pulsesToBinaryMapping = { + '01': '0' + '10': '1' + '2': '' + } + binaryToPulse = { + '0': '01' + '1': '10' + } + return protocolInfo = { + name: 'doorbell5' + type: 'switch' + values: + id: + type: "number" + unit: + type: "number" + brands: ["Smarthome WB008"] + pulseLengths: [200, 392, 6944] + pulseCount: 26 + decodePulses: (pulses) -> + src = pulses.substring(1) + binary = helper.map(src, pulsesToBinaryMapping) + return result = { + id: helper.binaryToNumber(binary, 0, 3), + unit: helper.binaryToNumber(binary, 4, 11), + } + encodeMessage: (message) -> + id = helper.map(helper.numberToBinary(message.id, 4), binaryToPulse) + unit = helper.map(helper.numberToBinary(message.unit, 8), binaryToPulse) + return "0#{id}#{unit}2" + } + diff --git a/test/lib-controller.coffee b/test/lib-controller.coffee index c82361a..cf4ae2a 100644 --- a/test/lib-controller.coffee +++ b/test/lib-controller.coffee @@ -947,6 +947,16 @@ describe '#decodePulses()', -> { id: 8, unit: 10 } ] }, + { + protocol: 'doorbell5' + pulseLengths: [ 200, 392, 6944 ], + pulses: [ + '00110101001010101011001012' + ], + values: [ + { id: 7, unit: 4 } + ] + }, { protocol: 'contact1' pulseLengths: [268, 1282, 2632, 10168] From 8ff90e4bce39cd5d97b776473ee6837a99ed1ce1 Mon Sep 17 00:00:00 2001 From: sofie Date: Thu, 18 Aug 2022 21:44:05 +0200 Subject: [PATCH 2/2] more testcases --- test/lib-controller.coffee | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/lib-controller.coffee b/test/lib-controller.coffee index cf4ae2a..aaa33c9 100644 --- a/test/lib-controller.coffee +++ b/test/lib-controller.coffee @@ -951,10 +951,32 @@ describe '#decodePulses()', -> protocol: 'doorbell5' pulseLengths: [ 200, 392, 6944 ], pulses: [ - '00110101001010101011001012' + '00110101001010101010110012' #A 1 7 2 + '00110101001010101011001012' #B 1 7 4 + '00110101001010101100101012' #C 1 7 8 + '01001101001010101011001012' #A 2 11 4 + '01001101001010101010110012' #B 2 11 2 + '01001101001010101100101012' #C 2 11 8 + '01010011001010101011001012' #A 3 13 4 + '01010011001010101010110012' #B 3 13 2 + '01010011001010101100101012' #C 3 13 8 + '01010100101010101011001012' #A 4 14 4 + '01010100101010101010110012' #B 4 14 2 + '01010100101010101100101012' #C 4 14 8 ], values: [ - { id: 7, unit: 4 } + { id: 7, unit: 2 } #A 1 + { id: 7, unit: 4 } #B 1 + { id: 7, unit: 8 } #C 1 + { id: 11, unit: 4 } #A 2 + { id: 11, unit: 2 } #B 2 + { id: 11, unit: 8 } #C 2 + { id: 13, unit: 4 } #A 3 + { id: 13, unit: 2 } #B 3 + { id: 13, unit: 8 } #C 3 + { id: 14, unit: 4 } #A 4 + { id: 14, unit: 2 } #B 4 + { id: 14, unit: 8 } #C 4 ] }, {