Advertisement
flybysun

DewPoint

Apr 17th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module.exports = (env) ->
  2.  
  3.   # Require the  bluebird promise library
  4.   Promise = env.require 'bluebird'
  5.  
  6.   # Require the [cassert library](https://github.com/rhoot/cassert).
  7.   assert = env.require 'cassert'
  8.  
  9.   # Include you own depencies with nodes global require function:
  10.   #  
  11.   #     someThing = require 'someThing'
  12.   #  
  13.   class Dewpoint extends env.plugins.Plugin
  14.    
  15.     init: (app, @framework, @config) =>
  16.       env.logger.info("Hello World")
  17.       deviceConfigDef = require("./device-config-schema")
  18.      
  19.       @framework.deviceManager.registerDeviceClass("DewpointDevice", {
  20.         configDef: deviceConfigDef.DewpointDevice,
  21.         createCallback: (config) => new DewpointDevice(config)
  22.       })
  23.  
  24.  
  25.   class DewpointDevice extends env.devices.TemperatureSensor
  26.     _temperature: null
  27.          
  28.     constructor: (@config) ->
  29.       @id = config.id
  30.       @name = config.name
  31.       @_temperature = lastState?.temperature?.value
  32.       super()
  33.    
  34.       @doYourStuff()
  35.       setInterval( ( => @doYourStuff() ), @config.interval)
  36.  
  37.     doYourStuff: ->
  38.       a=7.5
  39.       b=237.3
  40.       T=22  #temperature
  41.       H=40  #humidity
  42.  
  43.       sdd=6.1078 * Math.pow(10,(a*T)/(b+T))
  44.       dd=sdd*(H/100)
  45.       v=Math.log(dd/6.1078)/Math.log(10)
  46.       td=(b*v)/(a-v)
  47.     #console.log(td)
  48.       @_temperature = td
  49.       @emit 'temperature', td
  50.  
  51.     getTemperature: -> Promise.resolve(@_temperature)
  52.      
  53.   # ###Finally
  54.   # Create a instance of my plugin
  55.   Dewpoint = new Dewpoint
  56.   # and return it to the framework.
  57.   return Dewpoint
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement