Skip to content

Commit a2c5a85

Browse files
authored
Merge pull request #13 from jerryneedell/jerryn_cheer
add try/except to cheerlights demo
2 parents b1a1c29 + 5d9f5e1 commit a2c5a85

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

examples/espatcontrol_cheerlights.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ def get_value(response, location):
8383
print('-'*40)
8484
# For mystery reasons, there's two numbers before and after the json data
8585
lines = body.split(b'\r\n') # so split into lines
86-
value = get_value(lines[1], DATA_LOCATION) # an get the middle chunk
87-
builtin[0] = (100, 100, 100)
88-
if not value:
86+
try:
87+
value = get_value(lines[1], DATA_LOCATION) # an get the middle chunk
88+
builtin[0] = (100, 100, 100)
89+
if not value:
90+
continue
91+
print(times, the_time, "value:", value)
92+
except IndexError as e:
93+
print("IndexError processing Body, retrying\n", e)
8994
continue
90-
print(times, the_time, "value:", value)
91-
9295
if last_value != value:
9396
color = int(value[1:],16)
9497
red = color >> 16 & 0xFF

0 commit comments

Comments
 (0)