Skip to content

Commit

Permalink
Hue/saturation -> colortemp
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Jan 24, 2021
1 parent f8226da commit 4b1d1b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions converters/toZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,8 @@ const converters = {
const result = await converters.gledopto_light_color.convertSet(entity, key, value, meta);
if (result.state && result.state.color.hasOwnProperty('x') && result.state.color.hasOwnProperty('y')) {
result.state.color_temp = utils.xyToMireds(result.state.color.x, result.state.color.y);
} else if (result.state && result.state.color.hasOwnProperty('hue') && result.state.color.hasOwnProperty('saturation')) {
result.state.color_temp = utils.hueSaturationToMireds(result.state.color.hue, result.state.color.saturation);
}

return result;
Expand Down
7 changes: 7 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ function gammaCorrectRGB(r, g, b) {
return {r: Math.round(r*255), g: Math.round(g*255), b: Math.round(b*255)};
}

function hueSaturationToMireds(hue, saturation) {
const rgb = hsvToRGB(hue, saturation, 100);
const xy = rgbToXY(rgb.r, rgb.g, rgb.b);
return xyToMireds(xy.x, xy.y);
}

function hsvToRGB(h, s, v) {
h = h % 360 / 360;
s = s / 100;
Expand Down Expand Up @@ -512,6 +518,7 @@ module.exports = {
hasEndpoints,
miredsToXY,
xyToMireds,
hueSaturationToMireds,
gammaCorrectHSV,
gammaCorrectRGB,
isInRange,
Expand Down

0 comments on commit 4b1d1b8

Please sign in to comment.