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..aaa33c9 100644 --- a/test/lib-controller.coffee +++ b/test/lib-controller.coffee @@ -947,6 +947,38 @@ describe '#decodePulses()', -> { id: 8, unit: 10 } ] }, + { + protocol: 'doorbell5' + pulseLengths: [ 200, 392, 6944 ], + pulses: [ + '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: 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 + ] + }, { protocol: 'contact1' pulseLengths: [268, 1282, 2632, 10168]