From 73224897199ac8a176a080054039febe646cce2e Mon Sep 17 00:00:00 2001 From: hobbyquaker Date: Sat, 26 Jan 2019 21:32:28 +0100 Subject: [PATCH 1/4] add hue/saturation support to light_color --- converters/toZigbee.js | 46 +++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/converters/toZigbee.js b/converters/toZigbee.js index 1abf69a911a82..8920cae4a9526 100644 --- a/converters/toZigbee.js +++ b/converters/toZigbee.js @@ -236,7 +236,8 @@ const converters = { const cid = 'lightingColorCtrl'; if (type === 'set') { - // Check if we need to convert from RGB to XY. + // Check if we need to convert from RGB to XY and which cmd to use + let cmd; if (value.hasOwnProperty('r') && value.hasOwnProperty('g') && value.hasOwnProperty('b')) { const xy = utils.rgbToXY(value.r, value.g, value.b); value.x = xy.x; @@ -250,17 +251,48 @@ const converters = { const xy = utils.hexToXY(value.hex); value.x = xy.x; value.y = xy.y; + } else if (value.hasOwnProperty('hue') && value.hasOwnProperty('saturation')) { + value.hue = value.hue * (65535 / 360); + value.saturation = value.saturation * (2.54); + cmd = 'enhancedMoveToHueAndSaturation'; + } else if (value.hasOwnProperty('hue')) { + value.hue = value.hue * (65535 / 360); + cmd = 'enhancedMoveToHue'; + } else if (value.hasOwnProperty('saturation')) { + value.saturation = value.saturation * (2.54); + cmd = 'moveToSaturation'; + } + + const zclData = { + transtime: message.hasOwnProperty('transition') ? message.transition * 10 : 0, + }; + + switch (cmd) { + case 'enhancedMoveToHueAndSaturation': + zclData.enhancehue = value.hue; + zclData.saturation = value.saturation; + zclData.direction = value.direction || 0; + break; + case 'enhancedMoveToHue': + zclData.enhancehue = value.hue; + zclData.direction = value.direction || 0; + break; + + case 'moveToSaturation': + zclData.saturation = value.saturation; + break; + + default: + cmd = 'moveToColor'; + zclData.colorx = Math.round(value.x * 65535); + zclData.colory = Math.round(value.y * 65535); } return { cid: cid, - cmd: 'moveToColor', + cmd, cmdType: 'functional', - zclData: { - colorx: Math.round(value.x * 65535), - colory: Math.round(value.y * 65535), - transtime: message.hasOwnProperty('transition') ? message.transition * 10 : 0, - }, + zclData, cfg: cfg.default, readAfterWriteTime: message.hasOwnProperty('transition') ? message.transition * 1000 : 0, }; From a54b8ac0efa78ac62120ad8e7667bd3a339d247a Mon Sep 17 00:00:00 2001 From: hobbyquaker Date: Sun, 27 Jan 2019 00:00:07 +0100 Subject: [PATCH 2/4] add hue/saturation support to light_color_colortemp --- converters/fromZigbee.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/converters/fromZigbee.js b/converters/fromZigbee.js index 282c71ca85e15..7acdb31b9cbcf 100644 --- a/converters/fromZigbee.js +++ b/converters/fromZigbee.js @@ -550,7 +550,12 @@ const converters = { result.color_mode = msg.data.data['colorMode']; } - if (msg.data.data['currentX'] || msg.data.data['currentY']) { + if ( + msg.data.data['currentX'] + || msg.data.data['currentY'] + || msg.data.data['currentSaturation'] + || msg.data.data['enhancedCurrentHue'] + ) { result.color = {}; if (msg.data.data['currentX']) { @@ -560,6 +565,14 @@ const converters = { if (msg.data.data['currentY']) { result.color.y = precisionRound(msg.data.data['currentY'] / 65535, 3); } + + if (msg.data.data['currentSaturation']) { + result.color.saturation = precisionRound(msg.data.data['currentSaturation'] / 2.54, 1); + } + + if (msg.data.data['enhancedCurrentHue']) { + result.color.saturation = precisionRound(msg.data.data['enhancedCurrentHue'] / (65535 / 360), 1); + } } return result; From 2f33150151920ad8d51fe91484f3e61b59406c67 Mon Sep 17 00:00:00 2001 From: hobbyquaker Date: Sun, 27 Jan 2019 00:03:38 +0100 Subject: [PATCH 3/4] fix hue/saturation support to light_color_colortemp --- converters/fromZigbee.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/converters/fromZigbee.js b/converters/fromZigbee.js index 7acdb31b9cbcf..46c278fa1daba 100644 --- a/converters/fromZigbee.js +++ b/converters/fromZigbee.js @@ -571,7 +571,7 @@ const converters = { } if (msg.data.data['enhancedCurrentHue']) { - result.color.saturation = precisionRound(msg.data.data['enhancedCurrentHue'] / (65535 / 360), 1); + result.color.hue = precisionRound(msg.data.data['enhancedCurrentHue'] / (65535 / 360), 1); } } From 1679203c1a4633ca6fd10a6d6d53a7f21d602516 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 27 Jan 2019 00:13:59 +0100 Subject: [PATCH 4/4] Keep nodejs 4 support. --- converters/toZigbee.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/converters/toZigbee.js b/converters/toZigbee.js index 8920cae4a9526..08ba23c64623c 100644 --- a/converters/toZigbee.js +++ b/converters/toZigbee.js @@ -290,9 +290,9 @@ const converters = { return { cid: cid, - cmd, + cmd: cmd, cmdType: 'functional', - zclData, + zclData: zclData, cfg: cfg.default, readAfterWriteTime: message.hasOwnProperty('transition') ? message.transition * 1000 : 0, };