From ddd223aedff27105d81805671dac7fd13ae1b968 Mon Sep 17 00:00:00 2001 From: ebaauw Date: Fri, 17 Jan 2020 11:32:04 +0100 Subject: [PATCH] Update HueBridge.js - Add `Restart` charcacteristic to bridge accessory to restart Hue bridge or deCONZ gateway, see #599. --- lib/HueBridge.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/HueBridge.js b/lib/HueBridge.js index 92139737..6f03e2b6 100644 --- a/lib/HueBridge.js +++ b/lib/HueBridge.js @@ -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, @@ -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 @@ -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) } @@ -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()