Skip to content

Commit

Permalink
Update HueLight.js
Browse files Browse the repository at this point in the history
Add _Color Loop_ characteristic for colour lights.  See #475 and #597.
  • Loading branch information
ebaauw committed Jan 17, 2020
1 parent ddd223a commit fc224df
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions lib/HueLight.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ function HueLight (accessory, id, obj, type = 'light') {
this.checkSat(this.obj.state.sat)
}
}
if (this.config.colorloop) {
this.service.addOptionalCharacteristic(my.Characteristics.ColorLoop)
this.service.getCharacteristic(my.Characteristics.ColorLoop)
.on('set', this.setColorLoop.bind(this))
}
}
if (this.type === 'light') {
this.service.addOptionalCharacteristic(Characteristic.StatusFault)
Expand Down Expand Up @@ -542,6 +547,7 @@ HueLight.prototype.setConfig = function () {
bri: this.obj.state.bri !== undefined,
ct: this.obj.state.ct !== undefined,
xy: this.obj.state.xy !== undefined,
colorloop: this.obj.state.effect !== undefined,
wallSwitch: false,
outlet: this.bridge.outlet[this.type + 's'][this.id],
resetTimeout: this.bridge.platform.config.resetTimeout,
Expand Down Expand Up @@ -741,6 +747,7 @@ HueLight.prototype.checkState = function (state, event) {
this.checkCT(state.ct)
break
case 'effect':
this.checkEffect(state.effect)
break
case 'hue':
this.checkHue(state.hue)
Expand Down Expand Up @@ -1032,6 +1039,31 @@ HueLight.prototype.checkSat = function (sat) {
}
}

HueLight.prototype.checkEffect = function (effect) {
if (!this.config.colorloop) {
return
}
if (this.obj.state.effect !== effect) {
this.log.debug(
'%s: %s effect changed from %s to %s', this.name, this.type,
this.obj.state.effect, effect
)
this.obj.state.effect = effect
}
const hkColorloop = effect === 'colorloop'
if (this.hk.colorloop !== hkColorloop) {
if (this.hk.colorloop !== undefined) {
this.log.info(
'%s: set homekit colorloop from %s to %s', this.name,
this.hk.colorloop, hkColorloop
)
}
this.hk.colorloop = hkColorloop
this.service.getCharacteristic(my.Characteristics.ColorLoop)
.updateValue(this.hk.colorloop)
}
}

HueLight.prototype.checkReachable = function (reachable) {
if (this.obj.state.reachable !== reachable) {
this.log.debug(
Expand Down Expand Up @@ -1445,6 +1477,26 @@ HueLight.prototype.setSat = function (sat, callback) {
}
}

HueLight.prototype.setColorLoop = function (colorloop, callback) {
if (colorloop === this.hk.colorloop) {
return callback()
}
this.log.info(
'%s: homekit colorloop changed from %s to %s', this.name,
this.hk.colorloop, colorloop
)
const oldColorloop = this.hk.colorloop
this.hk.colorloop = colorloop
const newEffect = this.hk.colorloop ? 'colorloop' : 'none'
this.request({ effect: newEffect }).then(() => {
this.obj.state.effect = newEffect
callback()
}).catch((err) => {
this.hk.colorloop = oldColorloop
callback(err)
})
}

HueLight.prototype.setPosition = function (position, callback) {
if (position === this.hk.targetPosition) {
return callback()
Expand Down

0 comments on commit fc224df

Please sign in to comment.