DheerajKhajuria / pimatic-mysensors

mysensors
http://forum.mysensors.org/topic/797/pimatic-mysensors-controller-plugin
GNU General Public License v2.0
23 stars 24 forks source link

lux sensor #34

Closed sweebee closed 8 years ago

sweebee commented 9 years ago

I'm trying to add a lux sensor but i get these errors (depends where i put it between other devices):

error1: AssertionError: configDef must be an object
or error 2: warn: no plugin found for device "Battery" of class "MySensorsBattery"!

device:

class MySensorsLux extends env.devices.Device

    constructor: (@config,lastState, @board) ->
      @id = config.id
      @name = config.name

      @_lux = lastState?.lux?.value
      @_batterystat = lastState?.batterystat?.value
      #env.logger.info "MySensorsLux " , @id , @name
      @attributes = {}

      @attributes.battery = {
        description: "display the Battery level of Sensor"
        type: "number"
        unit: '%'
        acronym: 'BATT'
        hidden: !@config.batterySensor
       }

      @board.on("rfbattery", (result) =>
         if result.sender is @config.nodeid
          unless result.value is null or undefined
            @_batterystat =  parseInt(result.value)
            @emit "battery" , @_batterystat
      )

      @attributes.lux = {
        description: "the messured light in lux"
        type: "number"
        unit: 'lux'
      }

      @board.on("rfValue", (result) =>
        if result.sender is @config.nodeid
          if result.sensor is  @config.sensorid
            env.logger.info "<- MySensorsLux" , result
            if result.type is V_LIGHT_LEVEL or V_LEVEL
              @_lux = parseInt(result.value)
              @emit "lux", @_lux
      )
      super()

    getLux: -> Promise.resolve @_lux   
    getBattery: -> Promise.resolve @_batterystat
sweebee commented 8 years ago

fixed