diff --git a/src/controller.coffee b/src/controller.coffee index 025bba8..62a658c 100644 --- a/src/controller.coffee +++ b/src/controller.coffee @@ -9,7 +9,7 @@ protocols = [ 'switch26', 'switch27', 'switch28', 'switch29', 'switch30' 'rolling1' 'dimmer1', 'dimmer2' - 'pir1', 'pir2', 'pir3', 'pir4', 'pir5' + 'pir1', 'pir2', 'pir3', 'pir4', 'pir5', 'pir6' 'contact1', 'contact2', 'contact3', 'contact4' 'generic', 'generic2' 'alarm1', 'alarm2' diff --git a/src/protocols/pir6.coffee b/src/protocols/pir6.coffee new file mode 100644 index 0000000..34de7b0 --- /dev/null +++ b/src/protocols/pir6.coffee @@ -0,0 +1,36 @@ +module.exports = (helper) -> +# mapping for decoding + pulsesToBinaryMapping = { + '10': '1' #binary 1 + '01': '0' #binary 0 + '02': '' #footer + } + # same for send + binaryToPulse = { + '0': '01' + '1': '10' + } + return protocolInfo = { + name: 'pir6' + type: 'pir' + values: + id: + type: "number" + presence: + type: "boolean" + brands: ["Zanbo (ZABC86-1)", "Unknown (OSW-1-3 and OTW-1-3)"] + pulseLengths: [288, 864, 8964] + pulseCounts: [50] + decodePulses: (pulses) -> + binary = helper.map(pulses, pulsesToBinaryMapping) + # Pulses like: '001100001110100011000011' + # Translate to the following sequence + # 0011 0000 1110 1000 1100 0011 + # xxII IIII IIII IIII IIII IIII + # I: 24 bit ID (unsigned, MSB) + # x: ignored + return result = { + id: helper.binaryToNumber(binary, 2, 24) + presence: true + } + } diff --git a/test/lib-controller.coffee b/test/lib-controller.coffee index 77698b3..cb83bd2 100644 --- a/test/lib-controller.coffee +++ b/test/lib-controller.coffee @@ -69,6 +69,20 @@ describe '#decodePulses()', -> { id: 54099, unit: 21290, presence: true } ] }, + { + protocol: 'pir6' + pulseLengths: [ 288, 864, 8964 ] + pulses: [ + '01011010010101011010100110010101101001010101101002' + '01011010010101011010100110010101101001010110010102' + '01011010010101011010100110010101101001011001010102' + ] + values: [ + { id: 6410630, presence: true } + { id: 6410632, presence: true } + { id: 6410640, presence: true } + ] + }, { protocol: 'weather1' pulseLengths: [456, 1990, 3940, 9236] @@ -899,13 +913,13 @@ describe '#decodePulses()', -> it "#{t.protocol} should decode the pulses", -> for pulses, i in t.pulses results = controller.decodePulses(t.pulseLengths, pulses) - assert(results.length >= 1, "pulse of #{t.protocol} should be detected.") + assert(results.length >= 1, "pulse #{pulses} of #{t.protocol} should be detected.") result = null for r in results if r.protocol is t.protocol result = r break - assert(result, "pulse of #{t.protocol} should be detected as #{t.protocol}.") + assert(result, "pulse #{pulses} of #{t.protocol} should be detected as #{t.protocol}.") assert.deepEqual(result.values, t.values[i]) )