Skip to content

Commit 63951de

Browse files
authored
Add gradient to payload (diyhue#939)
* Adds gradient to payload * Replaces hex conversion with the built in one
1 parent 5249384 commit 63951de

File tree

1 file changed

+8
-1
lines changed
  • BridgeEmulator/lights/protocols

1 file changed

+8
-1
lines changed

BridgeEmulator/lights/protocols/mqtt.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import paho.mqtt.publish as publish
1212

1313
# internal functions
14-
from functions.colors import hsv_to_rgb
14+
from functions.colors import hsv_to_rgb, convert_xy
1515

1616
logging = logManager.logger.get_logger(__name__)
1717

@@ -35,6 +35,13 @@ def set_light(light, data):
3535
payload['brightness'] = value
3636
if key == "xy":
3737
payload['color'] = {'x': value[0], 'y': value[1]}
38+
if key == "gradient":
39+
rgbs = list(map(lambda xy_record: convert_xy(xy_record['color']['xy']['x'], xy_record['color']['xy']['y'], 255), value['points']))
40+
hexes = list(map(lambda rgb:
41+
"#" + format(int(round(rgb[0])), '02x') + format(int(round(rgb[1])), '02x') + format(int(round(rgb[2])), '02x'),
42+
rgbs))
43+
hexes.reverse()
44+
payload['gradient'] = hexes
3845
if key == "ct":
3946
payload["color_temp"] = value
4047
if key == "hue" or key == "sat":

0 commit comments

Comments
 (0)