Skip to content

Commit

Permalink
Merge pull request #115 from pimatic/issue-114
Browse files Browse the repository at this point in the history
added pir6 protocol and test cases, issue #114
  • Loading branch information
mwittig authored Sep 17, 2016
2 parents 49db3e5 + eee69d2 commit ecf252b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
36 changes: 36 additions & 0 deletions src/protocols/pir6.coffee
Original file line number Diff line number Diff line change
@@ -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
}
}
18 changes: 16 additions & 2 deletions test/lib-controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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])
)

Expand Down

0 comments on commit ecf252b

Please sign in to comment.