From 5d5fdf43cfab1e83fd9887b93467c187f5ff20ad Mon Sep 17 00:00:00 2001 From: CSylvain Date: Sun, 2 Dec 2018 11:03:14 -0500 Subject: [PATCH 1/3] 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. --- examples/tsl2561_simpletest.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/tsl2561_simpletest.py b/examples/tsl2561_simpletest.py index 9e13d91..56e084d 100644 --- a/examples/tsl2561_simpletest.py +++ b/examples/tsl2561_simpletest.py @@ -34,7 +34,7 @@ # Get raw (luminosity) readings using tuple unpacking #broadband, infrared = tsl.luminosity -# Get computed lux value +# Get computed lux value (tsl.lux can return None or a float) lux = tsl.lux # Print results @@ -43,7 +43,10 @@ print("Integration time = {}".format(tsl.integration_time)) print("Broadband = {}".format(broadband)) print("Infrared = {}".format(infrared)) -print("Lux = {}".format(lux)) +if lux != None: + print("Lux = {}".format(lux)) +else: + print("Lux = NaN") # Disble the light sensor (to save power) tsl.enabled = False From 38561c407e74af3cbe3cf488ab9910a21bb1539a Mon Sep 17 00:00:00 2001 From: CSylvain Date: Sun, 2 Dec 2018 11:10:08 -0500 Subject: [PATCH 2/3] change indent to make pylint happy is it happy now? --- examples/tsl2561_simpletest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tsl2561_simpletest.py b/examples/tsl2561_simpletest.py index 56e084d..a213162 100644 --- a/examples/tsl2561_simpletest.py +++ b/examples/tsl2561_simpletest.py @@ -44,9 +44,9 @@ print("Broadband = {}".format(broadband)) print("Infrared = {}".format(infrared)) if lux != None: - print("Lux = {}".format(lux)) + print("Lux = {}".format(lux)) else: - print("Lux = NaN") + print("Lux = NaN") # Disble the light sensor (to save power) tsl.enabled = False From 047793027d404b7b4a7b5080bcfb67649c33229a Mon Sep 17 00:00:00 2001 From: CSylvain Date: Tue, 4 Dec 2018 15:50:09 -0500 Subject: [PATCH 3/3] incorporates suggestions proposed changes --- examples/tsl2561_simpletest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tsl2561_simpletest.py b/examples/tsl2561_simpletest.py index a213162..21b9817 100644 --- a/examples/tsl2561_simpletest.py +++ b/examples/tsl2561_simpletest.py @@ -43,10 +43,10 @@ print("Integration time = {}".format(tsl.integration_time)) print("Broadband = {}".format(broadband)) print("Infrared = {}".format(infrared)) -if lux != None: +if lux is not None: print("Lux = {}".format(lux)) else: - print("Lux = NaN") + print("Lux value is None. Possible sensor underrange or overrange.") # Disble the light sensor (to save power) tsl.enabled = False