Skip to content

Commit

Permalink
Update entertainment.py
Browse files Browse the repository at this point in the history
update 1 non udp light per frame.#1057
  • Loading branch information
hendriksen-mark committed Dec 3, 2024
1 parent bd11e1c commit cb65ff8
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions BridgeEmulator/services/entertainment.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def entertainmentService(group, user):
esphomeLights = {}
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 @@ -239,12 +241,8 @@ def entertainmentService(group, user):
elif proto == "hue" and int(light.protocol_cfg["id"]) in hueGroupLights:
hueGroupLights[int(light.protocol_cfg["id"])] = [r,g,b]
else:
if frameID % 4 == 0: # can use 2, 4, 6, 8, 12 => increase in case the destination device is overloaded
operation = skipSimilarFrames(light.id_v1, light.state["xy"], light.state["bri"])
if operation == 1:
light.setV1State({"bri": light.state["bri"], "transitiontime": 3})
elif operation == 2:
light.setV1State({"xy": light.state["xy"], "transitiontime": 3})
if light not in non_UDP_lights:
non_UDP_lights.append(light)

frameID += 1
if frameID == 25:
Expand Down Expand Up @@ -285,6 +283,15 @@ def entertainmentService(group, user):
sock.sendto(udpdata, (ip.split(":")[0], wledLights[ip][segments]["udp_port"]))
if len(hueGroupLights) != 0:
h.send(hueGroupLights, hueGroup)
if len(non_UDP_lights) != 0:
light = non_UDP_lights[non_UDP_update_counter]
operation = skipSimilarFrames(light.id_v1, light.state["xy"], light.state["bri"])
if operation == 1:
light.setV1State({"bri": light.state["bri"], "transitiontime": 3})
elif operation == 2:
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
Expand Down

0 comments on commit cb65ff8

Please sign in to comment.