Skip to content

Commit 5d5fdf4

Browse files
authored
using tsl.lux can produce unanticipated Exception
using tsl.lux without consideration of all possible values will eventually produce an unanticipated Exception. return values can be a float, 0, or None. implicit datatype handling provides float(0) == 0.0 but float(None) will produce an Exception. alternatively, one should check isinstance( tsl.lux, Float ) but that would not explicitly show tsl.lux can be None in this example.
1 parent 986ccdf commit 5d5fdf4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

examples/tsl2561_simpletest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# Get raw (luminosity) readings using tuple unpacking
3535
#broadband, infrared = tsl.luminosity
3636

37-
# Get computed lux value
37+
# Get computed lux value (tsl.lux can return None or a float)
3838
lux = tsl.lux
3939

4040
# Print results
@@ -43,7 +43,10 @@
4343
print("Integration time = {}".format(tsl.integration_time))
4444
print("Broadband = {}".format(broadband))
4545
print("Infrared = {}".format(infrared))
46-
print("Lux = {}".format(lux))
46+
if lux != None:
47+
print("Lux = {}".format(lux))
48+
else:
49+
print("Lux = NaN")
4750

4851
# Disble the light sensor (to save power)
4952
tsl.enabled = False

0 commit comments

Comments
 (0)