Skip to content

Commit

Permalink
Update HueBridge.js
Browse files Browse the repository at this point in the history
- Add `Restart` charcacteristic to bridge accessory to restart Hue bridge or deCONZ gateway, see #599.
  • Loading branch information
ebaauw committed Jan 17, 2020
1 parent 0cf4376 commit ddd223a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/HueBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ HueBridge.prototype.exposeBridge = function (obj) {
this.config.nativeHomeKitSensors = false
/* falls through */
case 'BSB002': // Philips Hue v2 (square) bridge;
this.isHue = true
this.manufacturer = 'Philips'
this.idString = util.format(
'%s: %s %s %s v%s, api v%s', this.name, this.manufacturer,
Expand Down Expand Up @@ -181,6 +182,7 @@ HueBridge.prototype.exposeBridge = function (obj) {
}, 60000)
return d.promise
}
this.isDeconz = true
this.manufacturer = 'dresden elektronik'
this.type = 'gateway'
this.version = obj.swversion
Expand Down Expand Up @@ -250,6 +252,11 @@ HueBridge.prototype.exposeBridge = function (obj) {
this.service.getCharacteristic(my.Characteristics.TransitionTime)
.updateValue(this.state.transitiontime)
.on('set', this.setTransitionTime.bind(this))
if (this.isHue || this.isDeconz) {
this.service.getCharacteristic(my.Characteristics.Restart)
.updateValue(false)
.on('set', this.setRestart.bind(this))
}
this.accessoryList.push(this)
return deferred(true)
}
Expand Down Expand Up @@ -980,6 +987,30 @@ HueBridge.prototype.setTransitionTime = function (transitiontime, callback) {
return callback()
}

HueBridge.prototype.setRestart = function (restart, callback) {
if (!restart) {
return callback()
}
this.log.info('%s: restart', this.name)
let method = 'put'
let path = '/config'
let body = { reboot: true }
if (this.isDeconz) {
method = 'post'
path = '/config/restartapp'
body = undefined
}
this.request(method, path, body)
.then((obj) => {
setTimeout(() => {
this.service.setCharacteristic(my.Characteristics.Restart, false)
}, this.platform.config.resetTimeout)
return callback()
}).catch((err) => {
return callback(err)
})
}

HueBridge.prototype.identify = function (callback) {
this.log.info('%s: identify', this.name)
this.platform.identify()
Expand Down

0 comments on commit ddd223a

Please sign in to comment.