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

Update __init__.py to handle brightness values of "null" #951

Merged
merged 1 commit into from
Nov 17, 2023
Merged
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
24 changes: 21 additions & 3 deletions BridgeEmulator/HueObjects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,18 @@ def getV2Api(self):
result["color_temperature"]["mirek_valid"] = True if self.state[
"ct"] != None and self.state["ct"] < 500 and self.state["ct"] > 153 else False
if "bri" in self.state:
bri_value = self.state["bri"]
if bri_value is None or bri_value == "null":
bri_value = 1
result["dimming"] = {
"brightness": round(self.state["bri"] / 2.54, 2),
"min_dim_level": 0.10000000149011612
"brightness": round(float(bri_value) / 2.54, 2),
"min_dim_level": 0.1 # Adjust this value as needed
}
# if "bri" in self.state:
# result["dimming"] = {
# "brightness": round(self.state["bri"] / 2.54, 2),
# "min_dim_level": 0.10000000149011612
# }
result["dynamics"] = self.dynamics
result["id"] = self.id_v2
result["id_v1"] = "/lights/" + self.id_v1
Expand Down Expand Up @@ -1348,9 +1356,18 @@ def getV2Api(self):
if "on" in state:
v2State["on"] = {"on": state["on"]}
if "bri" in state:
bri_value = state["bri"]
if bri_value is None or bri_value == "null":
bri_value = 1
v2State["dimming"] = {
"brightness": round(state["bri"] / 2.54, 2)}
"brightness": round(float(bri_value) / 2.54, 2)
}
v2State["dimming_delta"] = {}

# if "bri" in state:
# v2State["dimming"] = {
# "brightness": round(state["bri"] / 2.54, 2)}
# v2State["dimming_delta"] = {}
if "xy" in state:
v2State["color"] = {
"xy": {"x": state["xy"][0], "y": state["xy"][1]}}
Expand Down Expand Up @@ -1889,3 +1906,4 @@ def save(self):
result["protocol"]=self.protocol
result["protocol_cfg"]=self.protocol_cfg
return result

Loading