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

Commit

Permalink
#37 HomeKit uses 1 and 0 for Characteristic.On, must be converted to …
Browse files Browse the repository at this point in the history
…bool
  • Loading branch information
michbeck100 committed Jun 20, 2016
1 parent 096f6e7 commit 2a773af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions accessories/switch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ module.exports = (env) ->
@addService(service, device.name)
.getCharacteristic(Characteristic.On)
.on 'set', (value, callback) =>
# HomeKit uses 0 or 1, must be converted to bool
if value is 1 then value = true
if value is 0 then value = false
if value is @_state
env.logger.debug 'value ' + value + ' equals current state of ' +
device.name + '. Not switching.'
Expand Down
16 changes: 16 additions & 0 deletions test/switch-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,19 @@ describe "switch", ->
device._state = null
device.fireChange()
assert device._state is null

it "should handle setting value to 1", ->
accessory._state = true
accessory.toggle(1)
assert device._state is null
accessory._state = false
accessory.toggle(1)
assert device._state is true

it "should handle setting value to 0", ->
accessory._state = false
accessory.toggle(0)
assert device._state is null
accessory._state = true
accessory.toggle(0)
assert device._state is false

0 comments on commit 2a773af

Please sign in to comment.