Skip to content

Commit

Permalink
Update HueLight.js
Browse files Browse the repository at this point in the history
- Expose Hue lights under manufacturer "Signify Netherlands B.V.";
- Only consider `xy` in `ct` colormode, for Hue and dresden elektronik lights that actually compute `xy` when setting `ct`, see #814.
  • Loading branch information
ebaauw committed Nov 19, 2020
1 parent dd417d3 commit d452ead
Showing 1 changed file with 42 additions and 33 deletions.
75 changes: 42 additions & 33 deletions lib/HueLight.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand All @@ -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 () {
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d452ead

Please sign in to comment.