Skip to content

Commit 729729a

Browse files
committed
Move light icon creation to get_lights function and only call on valid filtered lights
1 parent 248af50 commit 729729a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

logic/utils.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ def load_full_state(timeout=3):
4242

4343
data = r.json()
4444

45-
# Create icon for light
46-
for lid, light_data in data['lights'].iteritems():
47-
create_light_icon(lid, light_data)
48-
4945
workflow.store_data('full_state', data)
5046

5147

@@ -97,13 +93,21 @@ def get_lights(from_cache=False):
9793

9894
data = workflow.stored_data('full_state')
9995
lights = data['lights']
96+
10097
# Filter only lights that have a on/off state
10198
# This prevents issues with Deconz and Homekit hue bridges which set their config on a light
102-
return {
99+
filtered_lights = {
103100
lid: light for lid, light in lights.iteritems()
104101
if 'state' in lights[lid] and 'on' in lights[lid]['state']
105102
}
106103

104+
if not from_cache:
105+
# Create icon for lights
106+
for lid, light_data in filtered_lights.iteritems():
107+
create_light_icon(lid, light_data)
108+
109+
return filtered_lights
110+
107111

108112
def get_groups():
109113
data = workflow.stored_data('full_state')

0 commit comments

Comments
 (0)