Skip to content
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

Merged
merged 5 commits into from
Oct 16, 2018
Merged

Fix potential first read issue #17

merged 5 commits into from
Oct 16, 2018

Conversation

jerryneedell
Copy link

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.

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):
Copy link
Member

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):

Copy link
Author

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.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt tannewt merged commit 5493703 into adafruit:master Oct 16, 2018
@jerryneedell jerryneedell deleted the jerryn_None branch October 16, 2018 20:48
tannewt pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Oct 24, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DHT reading may be "None" if read too soon after boot
2 participants