Skip to content

Commit

Permalink
better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
flxdot committed Apr 18, 2024
1 parent 662fae2 commit f358a38
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/py_edge_device/carlos/edge/device/io/_dhtxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@ def read(self) -> dict[str, float]:

# Reading the DHT sensor is quite unreliable, as the device is not a real-time
# device. Thus, we just try it a couple of times and fail if it does not work.
last_error = None
for i in range(16):
try:
temperature, humidity = self._dht.read()
return {
"temperature": temperature,
"humidity": humidity,
}
except RuntimeError:
pass
except RuntimeError as ex:
last_error = ex

raise RuntimeError(f"Could not read {self._dht_type} sensor.")
raise last_error

0 comments on commit f358a38

Please sign in to comment.