Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
Fix FPS counter in entertainment.
Fix non udp lights in entertainment.
#1057
Exclude entertainment groups from scripts.
Add `LightGroup` as Zone. #1059
  • Loading branch information
hendriksen-mark committed Dec 17, 2024
1 parent cb65ff8 commit c195967
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion BridgeEmulator/HueObjects/Group.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, data):
self.id_v2 = data["id_v2"] if "id_v2" in data else genV2Uuid()
if "owner" in data:
self.owner = data["owner"]
self.icon_class = data["class"] if "class" in data else "Other"
self.icon_class = data["class"] if "class" in data else data["icon_class"] if "icon_class" in data else "Other"
self.lights = []
self.action = {"on": False, "bri": 100, "hue": 0, "sat": 254, "effect": "none", "xy": [
0.0, 0.0], "ct": 153, "alert": "none", "colormode": "xy"}
Expand Down
6 changes: 5 additions & 1 deletion BridgeEmulator/flaskUI/restful.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def post(self):

response[0]["success"]["clientkey"] = client_key
bridgeConfig["apiUsers"][username] = ApiUser.ApiUser(username, postDict["devicetype"], client_key)
logging.debug(response)
logging.info(response)
configManager.bridgeConfig.save_config()
return response
else:
Expand Down Expand Up @@ -173,6 +173,10 @@ def post(self, username, resource):
elif postDict["type"] == "Room":
v2Resource = "room"
bridgeConfig[resource][new_object_id] = Group.Group(postDict)
elif postDict["type"] == "LightGroup":
postDict["type"] = "Zone"
v2Resource = "zone"
bridgeConfig[resource][new_object_id] = Group.Group(postDict)
elif postDict["type"] == "Entertainment":
v2Resource = "entertainment_configuration"
bridgeConfig[resource][new_object_id] = EntertainmentConfiguration.EntertainmentConfiguration(postDict)
Expand Down
2 changes: 2 additions & 0 deletions BridgeEmulator/flaskUI/v2restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ def get(self, resource, resourceid):
return {"errors": [], "data": [object.getV2Api()]}
elif resource == "room":
return {"errors": [], "data": [object.getV2Room()]}
elif resource == "zone":
return {"errors": [], "data": [object.getV2Zone()]}
elif resource == "grouped_light":
return {"errors": [], "data": [object.getV2GroupedLight()]}
elif resource == "device":
Expand Down
9 changes: 5 additions & 4 deletions BridgeEmulator/functions/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def findScene(element):

def findGroup(id_v2):
for group, obj in bridgeConfig["groups"].items():
if obj.getV2Room()["id"] == id_v2:
return obj
elif obj.getV2Zone()["id"] == id_v2:
return obj
if obj.type != "Entertainment":
if obj.getV2Room()["id"] == id_v2:
return obj
elif obj.getV2Zone()["id"] == id_v2:
return obj
return False

def triggerScript(behavior_instance):
Expand Down
8 changes: 3 additions & 5 deletions BridgeEmulator/services/entertainment.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def entertainmentService(group, user):
hueGroupLights = {}
prev_frame_time = 0
new_frame_time = 0
prev_frameID = 0
non_UDP_update_counter = 0
for light in group.lights:
lights_v1[int(light().id_v1)] = light()
if light().protocol == "hue" and get_hue_entertainment_group(light(), group.name) != -1: # If the lights' Hue bridge has an entertainment group with the same name as this current group, we use it to sync the lights.
Expand Down Expand Up @@ -103,6 +103,7 @@ def entertainmentService(group, user):
p.stdout.read(1) # read one byte so the init function will correctly detect the frameBites
try:
while bridgeConfig["groups"][group.id_v1].stream["active"]:
new_frame_time = time.time()
if not init:
readByte = p.stdout.read(1)
logging.debug(readByte)
Expand All @@ -125,7 +126,6 @@ def entertainmentService(group, user):
mqttLights = []
wledLights = {}
non_UDP_lights = []
non_UDP_update_counter = 0
if data[:9].decode('utf-8') == "HueStream":
i = 0
apiVersion = 0
Expand Down Expand Up @@ -292,11 +292,9 @@ def entertainmentService(group, user):
light.setV1State({"xy": light.state["xy"], "transitiontime": 3})
non_UDP_update_counter = non_UDP_update_counter + 1 if non_UDP_update_counter < len(non_UDP_lights)-1 else 0

new_frame_time = time.time()
if new_frame_time - prev_frame_time > 1:
fps = frameID - prev_frameID
fps = 1.0 / (time.time() - new_frame_time)
prev_frame_time = new_frame_time
prev_frameID = frameID
logging.info("Entertainment FPS: " + str(fps))
else:
logging.info("HueStream was missing in the frame")
Expand Down

0 comments on commit c195967

Please sign in to comment.