Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for strictly use of xy color #1024

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion BridgeEmulator/lights/protocols/hue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logManager
import requests
from functions.colors import hsv_to_rgb, convert_rgb_xy

logging = logManager.logger.get_logger(__name__)

Expand All @@ -9,6 +10,20 @@ def set_light(light, data):
payload = {}
payload.update(data)
color = {}
if "strictusexy" in light.protocol_cfg and light.protocol_cfg["strictusexy"] and ("sat" in payload or "hue" in payload):
if "sat" in payload and "hue" in payload:
rgb = hsv_to_rgb(payload["hue"], payload["sat"], light.state["bri"])
del(payload["sat"])
del(payload["hue"])
elif "hue" in payload:
rgb = hsv_to_rgb(payload["hue"], light.state["sat"], light.state["bri"])
del(payload["hue"])
elif "sat" in payload:
rgb = hsv_to_rgb(light.state["hue"], payload["sat"], light.state["bri"])
del(payload["sat"])
xy = convert_rgb_xy(rgb[0],rgb[1],rgb[2])
color["colormode"] = 'xy'
color["xy"] = [xy[0], xy[1]]
if "xy" in payload:
color["xy"] = payload["xy"]
del(payload["xy"])
Expand Down Expand Up @@ -46,6 +61,6 @@ def discover(detectedLights, credentials):
modelid = "LTW001"
elif light["type"] == "On/Off plug-in unit":
modelid = "LOM001"
detectedLights.append({"protocol": "hue", "name": light["name"], "modelid": modelid, "protocol_cfg": {"ip": credentials["ip"], "hueUser": credentials["hueUser"], "modelid": light["modelid"], "id": id, "uniqueid": light["uniqueid"]}})
detectedLights.append({"protocol": "hue", "name": light["name"], "modelid": modelid, "protocol_cfg": {"ip": credentials["ip"], "hueUser": credentials["hueUser"], "modelid": light["modelid"], "id": id, "uniqueid": light["uniqueid"], "strictusexy": False}})
except Exception as e:
logging.info("Error connecting to Hue Bridge: %s", e)