From e0a60e7a88015444ed7411106820e73fa3620dbf Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 6 Nov 2024 07:03:32 -0600 Subject: [PATCH] timeout if remain busy during calibration --- adafruit_ahtx0.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/adafruit_ahtx0.py b/adafruit_ahtx0.py index 3d13553..aaf1c62 100644 --- a/adafruit_ahtx0.py +++ b/adafruit_ahtx0.py @@ -130,7 +130,12 @@ def calibrate(self) -> bool: except (RuntimeError, OSError): pass + start_busy_time = time.monotonic() while self.status & AHTX0_STATUS_BUSY: + if time.monotonic() - start_busy_time > 3.0: + raise RuntimeError( + "Sensor remained busy 3 seconds. Could not be calibrated" + ) time.sleep(0.01) if not self.status & AHTX0_STATUS_CALIBRATED: return False