3030""" 
3131
3232import  time 
33+ 
34+ try :
35+     # This is only needed for typing 
36+     import  busio   # pylint: disable=unused-import 
37+ except  ImportError :
38+     pass 
39+ 
40+ 
3341from  adafruit_bus_device .i2c_device  import  I2CDevice 
3442from  micropython  import  const 
3543
36- __version__  =  "0.0.0-auto.0" 
37- __repo__  =  "https://github.com/adafruit/Adafruit_CircuitPython_AHTx0.git" 
44+ __version__ :  str  =  "0.0.0-auto.0" 
45+ __repo__ :  str  =  "https://github.com/adafruit/Adafruit_CircuitPython_AHTx0.git" 
3846
39- AHTX0_I2CADDR_DEFAULT  =  const (0x38 )  # Default I2C address 
40- AHTX0_CMD_CALIBRATE  =  const (0xE1 )  # Calibration command 
41- AHTX0_CMD_TRIGGER  =  const (0xAC )  # Trigger reading command 
42- AHTX0_CMD_SOFTRESET  =  const (0xBA )  # Soft reset command 
43- AHTX0_STATUS_BUSY  =  const (0x80 )  # Status bit for busy 
44- AHTX0_STATUS_CALIBRATED  =  const (0x08 )  # Status bit for calibrated 
47+ AHTX0_I2CADDR_DEFAULT :  int  =  const (0x38 )  # Default I2C address 
48+ AHTX0_CMD_CALIBRATE :  int  =  const (0xE1 )  # Calibration command 
49+ AHTX0_CMD_TRIGGER :  int  =  const (0xAC )  # Trigger reading command 
50+ AHTX0_CMD_SOFTRESET :  int  =  const (0xBA )  # Soft reset command 
51+ AHTX0_STATUS_BUSY :  int  =  const (0x80 )  # Status bit for busy 
52+ AHTX0_STATUS_CALIBRATED :  int  =  const (0x08 )  # Status bit for calibrated 
4553
4654
4755class  AHTx0 :
@@ -78,7 +86,7 @@ class AHTx0:
7886
7987    """ 
8088
81-     def  __init__ (self , i2c_bus , address = AHTX0_I2CADDR_DEFAULT ):
89+     def  __init__ (self , i2c_bus :  busio . I2C , address :  int   =   AHTX0_I2CADDR_DEFAULT ):
8290        time .sleep (0.02 )  # 20ms delay to wake up 
8391        self .i2c_device  =  I2CDevice (i2c_bus , address )
8492        self ._buf  =  bytearray (6 )
@@ -88,14 +96,14 @@ def __init__(self, i2c_bus, address=AHTX0_I2CADDR_DEFAULT):
8896        self ._temp  =  None 
8997        self ._humidity  =  None 
9098
91-     def  reset (self ):
99+     def  reset (self )  ->   None :
92100        """Perform a soft-reset of the AHT""" 
93101        self ._buf [0 ] =  AHTX0_CMD_SOFTRESET 
94102        with  self .i2c_device  as  i2c :
95103            i2c .write (self ._buf , start = 0 , end = 1 )
96104        time .sleep (0.02 )  # 20ms delay to wake up 
97105
98-     def  calibrate (self ):
106+     def  calibrate (self )  ->   bool :
99107        """Ask the sensor to self-calibrate. Returns True on success, False otherwise""" 
100108        self ._buf [0 ] =  AHTX0_CMD_CALIBRATE 
101109        self ._buf [1 ] =  0x08 
@@ -109,26 +117,26 @@ def calibrate(self):
109117        return  True 
110118
111119    @property  
112-     def  status (self ):
120+     def  status (self )  ->   int :
113121        """The status byte initially returned from the sensor, see datasheet for details""" 
114122        with  self .i2c_device  as  i2c :
115123            i2c .readinto (self ._buf , start = 0 , end = 1 )
116124        # print("status: "+hex(self._buf[0])) 
117125        return  self ._buf [0 ]
118126
119127    @property  
120-     def  relative_humidity (self ):
128+     def  relative_humidity (self )  ->   int :
121129        """The measured relative humidity in percent.""" 
122130        self ._readdata ()
123131        return  self ._humidity 
124132
125133    @property  
126-     def  temperature (self ):
134+     def  temperature (self )  ->   int :
127135        """The measured temperature in degrees Celsius.""" 
128136        self ._readdata ()
129137        return  self ._temp 
130138
131-     def  _readdata (self ):
139+     def  _readdata (self )  ->   None :
132140        """Internal function for triggering the AHT to read temp/humidity""" 
133141        self ._buf [0 ] =  AHTX0_CMD_TRIGGER 
134142        self ._buf [1 ] =  0x33 
0 commit comments