Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support mutiple devices #14

Merged
merged 3 commits into from
Jun 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion devices/base.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ module.exports = (env) ->
params:
brightnessValue:
type: t.number
changeDimlevelTo:
description: "Sets the level of the dimmer"
params:
dimlevel:
type: t.number

constructor: (initState) ->
unless @device
Expand Down Expand Up @@ -118,7 +123,8 @@ module.exports = (env) ->
turnOff: -> throw new Error "Function 'turnOff' is not implemented!"
setColor: -> throw new Error "Function 'setColor' is not implemented!"
setWhite: -> throw new Error "Function 'setWhite' is not implemented!"
setBrightness: -> throw new Error "Function 'setBrightness' is not implemented!"
setBrightness: (brightnessValue) -> throw new Error "Function 'setBrightness' is not implemented!"
changeDimlevelTo: (dimLevel) -> @setBrightness(dimLevel)

toggle: ->
if @power is 'on' then @turnOn() else @turnOff()
Expand Down
17 changes: 14 additions & 3 deletions devices/milight.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ module.exports = (env) ->
Promise.resolve()

setColor: (newColor) ->
color = Color(newColor).rgb()
r = Number("0x#{newColor[1..2]}")
g = Number("0x#{newColor[3..4]}")
b = Number("0x#{newColor[5..6]}")
if r == 255 && g == 255 && b == 255
return @setWhite()

@device.sendCommands(nodeMilight.commands.rgbw.on(@zone), nodeMilight.commands.rgbw.rgb255(r, g, b))

@_updateState
mode: @COLOR_MODE
color: color
Expand All @@ -52,8 +59,12 @@ module.exports = (env) ->
Promise.resolve()

setWhite: () ->
@_updateState mode: @WHITE_MODE
@device.sendCommands(nodeMilight.commands.rgbw.whiteMode(@zone)) if @power
@device.sendCommands(nodeMilight.commands.rgbw.whiteMode(@zone))

@_updateState
mode: @WHITE_MODE

@setBrightness @brightnessb
Promise.resolve()

setBrightness: (newBrightness) ->
Expand Down