diff --git a/lib/HueLight.js b/lib/HueLight.js index d6f7e497..2f31e9f2 100644 --- a/lib/HueLight.js +++ b/lib/HueLight.js @@ -56,6 +56,7 @@ const knownLights = { }, 'dresden elektronik': { // See: https://www.dresden-elektronik.de/funktechnik/solutions/wireless-light-control/wireless-ballasts/?L=1 + computesXy: true }, FeiBit: { models: { @@ -161,7 +162,9 @@ const knownLights = { }, Pee: { // Issue #217 }, - Philips: { + ShenZhen_Homa: { // PR #234, issue #235 + }, + 'Signify Netherlands B.V.': { // See: http://www.developers.meethue.com/documentation/supported-lights gamuts: { // Color gamut per light model. A: { // Color Lights @@ -180,6 +183,10 @@ const knownLights = { b: [0.1530, 0.0480] } }, + computesXy: true, + fix: () => { + this.manufacturer = 'Signify Netherlands B.V.' + }, models: { LLC001: { // Living Colors Gen1 Iris fix: function () { @@ -214,12 +221,10 @@ const knownLights = { LST001: { gamut: 'A' }, // Hue LightStrips LST002: { gamut: 'C' } // Hue LightStrips Plus } - }, - ShenZhen_Homa: { // PR #234, issue #235 } } -knownLights['Signify Netherlands B.V.'] = knownLights.Philips +knownLights.Philips = knownLights['Signify Netherlands B.V.'] function dateToString (date, utc = true) { if (date == null || date === 'none') { @@ -595,6 +600,9 @@ HueLight.prototype.setConfig = function () { this.bridge.name, this.resource, this.obj ) } + if (manufacturer.computesXy) { + this.config.computesXy = true + } } if (model.noAlert) { this.config.noAlert = true @@ -605,9 +613,6 @@ HueLight.prototype.setConfig = function () { if (model.noWaitUpdate) { this.config.waitTimeUpdate = 0 } - if (model.adaptiveLighting) { - this.config.adaptiveLighting = true - } this.log.debug('%s: %s: config: %j', this.bridge.name, this.resource, this.config) } @@ -1039,29 +1044,31 @@ HueLight.prototype.checkXy = function (xy, fromCt = false) { } this.obj.state.xy = xy } - const hs = xyToHueSaturation(this.obj.state.xy, this.config.gamut) - const hkHue = hs.hue - const hkSat = hs.sat - if (this.hk.hue !== hkHue) { - if (this.hk.hue !== undefined) { - this.log.info( - '%s: set homekit hue from %s˚ to %s˚', this.name, this.hk.hue, hkHue - ) + if (this.obj.state.colormode === 'xy' || fromCt || this.config.computesXy) { + const hs = xyToHueSaturation(this.obj.state.xy, this.config.gamut) + const hkHue = hs.hue + const hkSat = hs.sat + if (this.hk.hue !== hkHue) { + if (this.hk.hue !== undefined) { + this.log.info( + '%s: set homekit hue from %s˚ to %s˚', this.name, this.hk.hue, hkHue + ) + } + this.hk.hue = hkHue + this.service.getCharacteristic(Characteristic.Hue) + .updateValue(this.hk.hue) } - this.hk.hue = hkHue - this.service.getCharacteristic(Characteristic.Hue) - .updateValue(this.hk.hue) - } - if (this.hk.sat !== hkSat) { - if (this.hk.sat !== undefined) { - this.log.info( - '%s: set homekit saturation from %s%% to %s%%', this.name, - this.hk.sat, hkSat - ) + if (this.hk.sat !== hkSat) { + if (this.hk.sat !== undefined) { + this.log.info( + '%s: set homekit saturation from %s%% to %s%%', this.name, + this.hk.sat, hkSat + ) + } + this.hk.sat = hkSat + this.service.getCharacteristic(Characteristic.Saturation) + .updateValue(this.hk.sat) } - this.hk.sat = hkSat - this.service.getCharacteristic(Characteristic.Saturation) - .updateValue(this.hk.sat) } } @@ -1492,6 +1499,7 @@ HueLight.prototype.setCt = function (ct, callback) { const newCt = this.hk.ct this.put({ ct: newCt }).then(() => { this.obj.state.ct = newCt + this.obj.state.colormode = 'ct' this.checkXy(ctToXy(this.obj.state.ct), true) callback() }).catch((error) => { @@ -1522,10 +1530,11 @@ HueLight.prototype.setHue = function (hue, callback) { this.disableAdaptiveLighting() const oldHue = this.hk.hue this.hk.hue = hue - if (this.config.xy) { + if (this.config.xy && this.hk.sat != null) { const newXy = hueSaturationToXy(this.hk.hue, this.hk.sat, this.config.gamut) this.put({ xy: newXy }).then(() => { this.obj.state.xy = newXy + this.obj.state.colormode = 'xy' callback() }).catch((error) => { this.hk.hue = oldHue @@ -1535,6 +1544,7 @@ HueLight.prototype.setHue = function (hue, callback) { const newHue = Math.round(this.hk.hue * 65535.0 / 360.0) this.put({ hue: newHue }).then(() => { this.obj.state.hue = newHue + this.obj.state.colormode = 'hs' callback() }).catch((error) => { this.hk.hue = oldHue @@ -1554,10 +1564,11 @@ HueLight.prototype.setSat = function (sat, callback) { this.disableAdaptiveLighting() const oldSat = this.hk.sat this.hk.sat = sat - if (this.config.xy) { + if (this.config.xy && this.hk.hue != null) { const newXy = hueSaturationToXy(this.hk.hue, this.hk.sat, this.config.gamut) this.put({ xy: newXy }).then(() => { this.obj.state.xy = newXy + this.obj.state.colormode = 'xy' callback() }).catch((error) => { this.hk.sat = oldSat @@ -1567,6 +1578,7 @@ HueLight.prototype.setSat = function (sat, callback) { const newSat = Math.round(this.hk.sat * 254.0 / 100.0) this.put({ sat: newSat }).then(() => { this.obj.state.sat = newSat + this.obj.state.colormode = 'hs' callback() }).catch((error) => { this.hk.sat = oldSat @@ -1877,9 +1889,6 @@ HueLight.prototype._put = function () { desiredState.transitiontime = this.bridge.state.transitiontime * 10 this.bridge.resetTransitionTime() } - if (desiredState.ct != null) { - delete desiredState.xy - } this.bridge.request('put', this.resourcePath, desiredState).then((obj) => { this.recentlyUpdated = true for (const d of deferrals) {