pimatic / rfcontroljs

nodejs modul with protocol support for different 433mhz switches and weather stations for the RFControl Arduino library.
GNU General Public License v3.0
49 stars 54 forks source link

Creating a RAW switch #97

Closed rrooggiieerr closed 8 years ago

rrooggiieerr commented 8 years ago

I have created a RAW switch which outputs the set pulses directly to pimatic:

The protocol src/protocols/raw.coffee

module.exports = (helper) ->
  return protocolInfo = {
    name: 'raw'
    type: 'switch'
    values:
      pulseCount:
        type: "number"
      pulseLengths:
        type: "object"
      pulsesOn:
        type: "string"
      pulsesOff:
        type: "string"
    brands: ["RAW"]
    pulseLengths: []
    pulseCount: 0
    decodePulses: (pulses) ->
      # Currently only encodeMessage is supported
      return null
    encodeMessage: (message) ->
      this.pulseLengths =  message.pulseLengths
      pulses = (if message.state then message.pulsesOn else message.pulsesOff )
      return pulses
  }

I also needed to update src/controller.coffee, I switched lines 171 and 172 so the protocol.pulseLengths is read after protocol.encodeMessage(message) is executed from:

171       pulseLengths: protocol.pulseLengths
172       pulses: protocol.encodeMessage(message)

to:

171       pulses: protocol.encodeMessage(message)
172       pulseLengths: protocol.pulseLengths

The config in pimatic:

    {
      "id": "test-raw",
      "name": "Test RAW",
      "class": "HomeduinoRFSwitch",
      "protocols": [
        {
          "name": "raw",
          "options": {
            "pulseCount": 58,
            "pulseLengths": [
              222,
              438,
              952,
              5028
            ],
            "pulsesOn": "2121210202210202212102020221212121022102212121212102022103",
            "pulsesOff": "2121210202210221020202212121022102210202020221210221022103"
          },
          "send": true,
          "receive": false
        }
      ]
    }

How should I be able to also support decodePulses?