Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = (env) ->
- # Require the bluebird promise library
- Promise = env.require 'bluebird'
- # Require the [cassert library](https://github.com/rhoot/cassert).
- assert = env.require 'cassert'
- # Include you own depencies with nodes global require function:
- #
- # someThing = require 'someThing'
- #
- class Dewpoint extends env.plugins.Plugin
- init: (app, @framework, @config) =>
- env.logger.info("Hello World")
- deviceConfigDef = require("./device-config-schema")
- @framework.deviceManager.registerDeviceClass("DewpointDevice", {
- configDef: deviceConfigDef.DewpointDevice,
- createCallback: (config) => new DewpointDevice(config)
- })
- class DewpointDevice extends env.devices.TemperatureSensor
- _temperature: null
- constructor: (@config) ->
- @id = config.id
- @name = config.name
- @_temperature = lastState?.temperature?.value
- super()
- @doYourStuff()
- setInterval( ( => @doYourStuff() ), @config.interval)
- doYourStuff: ->
- a=7.5
- b=237.3
- T=22 #temperature
- H=40 #humidity
- sdd=6.1078 * Math.pow(10,(a*T)/(b+T))
- dd=sdd*(H/100)
- v=Math.log(dd/6.1078)/Math.log(10)
- td=(b*v)/(a-v)
- #console.log(td)
- @_temperature = td
- @emit 'temperature', td
- getTemperature: -> Promise.resolve(@_temperature)
- # ###Finally
- # Create a instance of my plugin
- Dewpoint = new Dewpoint
- # and return it to the framework.
- return Dewpoint
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement