-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix potential first read issue #17
Conversation
adafruit_dht.py
Outdated
@@ -138,7 +138,8 @@ def measure(self): | |||
delay_between_readings = 0.5 | |||
if self._dht11: | |||
delay_between_readings = 1.0 | |||
if time.monotonic()-self._last_called > delay_between_readings: | |||
if (self._last_called == 0) or \ | |||
(time.monotonic()-self._last_called > delay_between_readings): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the \ line wrap error prone. Instead, I use parens:
if (self._last_called == 0 or
(time.monotonic() - self._last_called) > delay_between_readings):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done -- I also added a comment to explain why this was added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Updating https://github.com/adafruit/Adafruit_CircuitPython_DHT to 3.2.1 from 3.2.0: > Merge pull request adafruit/Adafruit_CircuitPython_DHT#18 from jerryneedell/jerryn_fix_pr_14 > Merge pull request adafruit/Adafruit_CircuitPython_DHT#17 from jerryneedell/jerryn_None > ignore the board module imports in .pylintrc Updating https://github.com/adafruit/Adafruit_CircuitPython_Slideshow to 1.0.1 from 1.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_Slideshow#8 from kattni/folder-fix
fixes #16
IF self._last_called == 0 then we know that no read has ever been attempted.
This eliminates the chance of a "silent" failure and a return of None without throwing a Runtime error as well.