File tree 1 file changed +15
-9
lines changed
1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -106,15 +106,21 @@ def reset(self) -> None:
106
106
time .sleep (0.02 ) # 20ms delay to wake up
107
107
108
108
def calibrate (self ) -> bool :
109
- """Ask the sensor to self-calibrate. May not 'succeed' on newer AHT20s."""
110
- self ._buf [0 ] = AHTX0_CMD_CALIBRATE
111
- self ._buf [1 ] = 0x08
112
- self ._buf [2 ] = 0x00
113
- with self .i2c_device as i2c :
114
- i2c .write (self ._buf , start = 0 , end = 3 )
115
- while self .status & AHTX0_STATUS_BUSY :
116
- time .sleep (0.01 )
117
- return True
109
+ """Ask the sensor to self-calibrate. Returns True on success, False otherwise"""
110
+ """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 :
116
+ 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
+ return True
122
+ except :
123
+ pass
118
124
119
125
@property
120
126
def status (self ) -> int :
You can’t perform that action at this time.
0 commit comments