Skip to content

Commit fe1abce

Browse files
committed
moving try/except
1 parent e586707 commit fe1abce

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

adafruit_ahtx0.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,18 @@ def reset(self) -> None:
108108
def calibrate(self) -> bool:
109109
"""Ask the sensor to self-calibrate. Returns True on success, False otherwise"""
110110
# Newer AHT20's may not succeed, so wrapping in try/except
111-
try:
112-
self._buf[0] = AHTX0_CMD_CALIBRATE
113-
self._buf[1] = 0x08
114-
self._buf[2] = 0x00
115-
with self.i2c_device as i2c:
111+
self._buf[0] = AHTX0_CMD_CALIBRATE
112+
self._buf[1] = 0x08
113+
self._buf[2] = 0x00
114+
with self.i2c_device as i2c:
115+
try:
116116
i2c.write(self._buf, start=0, end=3)
117-
while self.status & AHTX0_STATUS_BUSY:
118-
time.sleep(0.01)
119-
if not self.status & AHTX0_STATUS_CALIBRATED:
120-
return False
121-
except Exception: # pylint: disable=broad-except
122-
pass
117+
except Exception: # pylint: disable=broad-except
118+
pass
119+
while self.status & AHTX0_STATUS_BUSY:
120+
time.sleep(0.01)
121+
if not self.status & AHTX0_STATUS_CALIBRATED:
122+
return False
123123
return True
124124

125125
@property

0 commit comments

Comments
 (0)