-
Notifications
You must be signed in to change notification settings - Fork 1
/
nanoleaf.coffee
34 lines (24 loc) · 1.04 KB
/
nanoleaf.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Pimatic MQTT plugin
module.exports = (env) ->
Promise = env.require 'bluebird'
pluginConfigDef = require './nanoleaf-config-schema'
deviceTypes = {}
for device in [
'light-aurora'
]
deviceName = device.replace /(^[a-z])|(\-[a-z])/g, ($1) -> $1.toUpperCase()
className = device.replace /(^[a-z])|(\-[a-z])/g, ($1) -> $1.toUpperCase().replace('-','')
deviceTypes[className] = require('./devices/' + device)(env)
class NanloafPlugin extends env.plugins.Plugin
init: (app, @framework, @config) =>
deviceConfigDef = require("./device-config-schema")
for className, classType of deviceTypes
env.logger.debug "Registering device class #{deviceName}"
@framework.deviceManager.registerDeviceClass(deviceName, {
configDef: deviceConfigDef[className],
createCallback: @callbackHandler(className, classType)
})
callbackHandler: (className, classType) ->
return (config, lastState) =>
return new classType(config, @, lastState)
return new NanloafPlugin