Skip to content

Commit c195967

Browse files
fixes
Fix FPS counter in entertainment. Fix non udp lights in entertainment. #1057 Exclude entertainment groups from scripts. Add `LightGroup` as Zone. #1059
1 parent cb65ff8 commit c195967

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

BridgeEmulator/HueObjects/Group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, data):
1515
self.id_v2 = data["id_v2"] if "id_v2" in data else genV2Uuid()
1616
if "owner" in data:
1717
self.owner = data["owner"]
18-
self.icon_class = data["class"] if "class" in data else "Other"
18+
self.icon_class = data["class"] if "class" in data else data["icon_class"] if "icon_class" in data else "Other"
1919
self.lights = []
2020
self.action = {"on": False, "bri": 100, "hue": 0, "sat": 254, "effect": "none", "xy": [
2121
0.0, 0.0], "ct": 153, "alert": "none", "colormode": "xy"}

BridgeEmulator/flaskUI/restful.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def post(self):
8989

9090
response[0]["success"]["clientkey"] = client_key
9191
bridgeConfig["apiUsers"][username] = ApiUser.ApiUser(username, postDict["devicetype"], client_key)
92-
logging.debug(response)
92+
logging.info(response)
9393
configManager.bridgeConfig.save_config()
9494
return response
9595
else:
@@ -173,6 +173,10 @@ def post(self, username, resource):
173173
elif postDict["type"] == "Room":
174174
v2Resource = "room"
175175
bridgeConfig[resource][new_object_id] = Group.Group(postDict)
176+
elif postDict["type"] == "LightGroup":
177+
postDict["type"] = "Zone"
178+
v2Resource = "zone"
179+
bridgeConfig[resource][new_object_id] = Group.Group(postDict)
176180
elif postDict["type"] == "Entertainment":
177181
v2Resource = "entertainment_configuration"
178182
bridgeConfig[resource][new_object_id] = EntertainmentConfiguration.EntertainmentConfiguration(postDict)

BridgeEmulator/flaskUI/v2restapi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ def get(self, resource, resourceid):
576576
return {"errors": [], "data": [object.getV2Api()]}
577577
elif resource == "room":
578578
return {"errors": [], "data": [object.getV2Room()]}
579+
elif resource == "zone":
580+
return {"errors": [], "data": [object.getV2Zone()]}
579581
elif resource == "grouped_light":
580582
return {"errors": [], "data": [object.getV2GroupedLight()]}
581583
elif resource == "device":

BridgeEmulator/functions/scripts.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ def findScene(element):
1818

1919
def findGroup(id_v2):
2020
for group, obj in bridgeConfig["groups"].items():
21-
if obj.getV2Room()["id"] == id_v2:
22-
return obj
23-
elif obj.getV2Zone()["id"] == id_v2:
24-
return obj
21+
if obj.type != "Entertainment":
22+
if obj.getV2Room()["id"] == id_v2:
23+
return obj
24+
elif obj.getV2Zone()["id"] == id_v2:
25+
return obj
2526
return False
2627

2728
def triggerScript(behavior_instance):

BridgeEmulator/services/entertainment.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def entertainmentService(group, user):
6868
hueGroupLights = {}
6969
prev_frame_time = 0
7070
new_frame_time = 0
71-
prev_frameID = 0
71+
non_UDP_update_counter = 0
7272
for light in group.lights:
7373
lights_v1[int(light().id_v1)] = light()
7474
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.
@@ -103,6 +103,7 @@ def entertainmentService(group, user):
103103
p.stdout.read(1) # read one byte so the init function will correctly detect the frameBites
104104
try:
105105
while bridgeConfig["groups"][group.id_v1].stream["active"]:
106+
new_frame_time = time.time()
106107
if not init:
107108
readByte = p.stdout.read(1)
108109
logging.debug(readByte)
@@ -125,7 +126,6 @@ def entertainmentService(group, user):
125126
mqttLights = []
126127
wledLights = {}
127128
non_UDP_lights = []
128-
non_UDP_update_counter = 0
129129
if data[:9].decode('utf-8') == "HueStream":
130130
i = 0
131131
apiVersion = 0
@@ -292,11 +292,9 @@ def entertainmentService(group, user):
292292
light.setV1State({"xy": light.state["xy"], "transitiontime": 3})
293293
non_UDP_update_counter = non_UDP_update_counter + 1 if non_UDP_update_counter < len(non_UDP_lights)-1 else 0
294294

295-
new_frame_time = time.time()
296295
if new_frame_time - prev_frame_time > 1:
297-
fps = frameID - prev_frameID
296+
fps = 1.0 / (time.time() - new_frame_time)
298297
prev_frame_time = new_frame_time
299-
prev_frameID = frameID
300298
logging.info("Entertainment FPS: " + str(fps))
301299
else:
302300
logging.info("HueStream was missing in the frame")

0 commit comments

Comments
 (0)