Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
#14: using turnOn and turnOff methods for switches. This decouples di…
Browse files Browse the repository at this point in the history
…fferent value types for Characteristic.On and fixes predicate handling
  • Loading branch information
michbeck100 committed Jan 3, 2016
1 parent 0bfc894 commit dc3d7c8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
9 changes: 1 addition & 8 deletions accessories/dimmer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ module.exports = (env) ->
@addService(Service.Lightbulb, device.name)
.getCharacteristic(Characteristic.On)
.on 'set', (value, callback) =>
if device._state == value
callback()
return
promise = null
if value
promise = device.turnOn()
else
promise = device.turnOff()
promise = if value then device.turnOn() else device.turnOff()
@handleVoidPromise(promise, callback)

@getService(Service.Lightbulb)
Expand Down
6 changes: 2 additions & 4 deletions accessories/powerswitch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ module.exports = (env) ->
@addService(Service.Switch, device.name)
.getCharacteristic(Characteristic.On)
.on 'set', (value, callback) =>
if device._state == value
callback()
return
@handleVoidPromise(device.changeStateTo(value), callback)
promise = if value then device.turnOn() else device.turnOff()
@handleVoidPromise(promise, callback)

@getService(Service.Switch)
.getCharacteristic(Characteristic.On)
Expand Down

0 comments on commit dc3d7c8

Please sign in to comment.