30
30
"""
31
31
32
32
import time
33
+ import busio
34
+
33
35
from adafruit_bus_device .i2c_device import I2CDevice
34
36
from micropython import const
35
37
36
- __version__ = "0.0.0-auto.0"
37
- __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_AHTx0.git"
38
+ __version__ : str = "0.0.0-auto.0"
39
+ __repo__ : str = "https://github.com/adafruit/Adafruit_CircuitPython_AHTx0.git"
38
40
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
41
+ AHTX0_I2CADDR_DEFAULT : int = const (0x38 ) # Default I2C address
42
+ AHTX0_CMD_CALIBRATE : int = const (0xE1 ) # Calibration command
43
+ AHTX0_CMD_TRIGGER : int = const (0xAC ) # Trigger reading command
44
+ AHTX0_CMD_SOFTRESET : int = const (0xBA ) # Soft reset command
45
+ AHTX0_STATUS_BUSY : int = const (0x80 ) # Status bit for busy
46
+ AHTX0_STATUS_CALIBRATED : int = const (0x08 ) # Status bit for calibrated
45
47
46
48
47
49
class AHTx0 :
@@ -78,7 +80,7 @@ class AHTx0:
78
80
79
81
"""
80
82
81
- def __init__ (self , i2c_bus , address = AHTX0_I2CADDR_DEFAULT ):
83
+ def __init__ (self , i2c_bus : busio . I2C , address : int = AHTX0_I2CADDR_DEFAULT ):
82
84
time .sleep (0.02 ) # 20ms delay to wake up
83
85
self .i2c_device = I2CDevice (i2c_bus , address )
84
86
self ._buf = bytearray (6 )
@@ -88,14 +90,14 @@ def __init__(self, i2c_bus, address=AHTX0_I2CADDR_DEFAULT):
88
90
self ._temp = None
89
91
self ._humidity = None
90
92
91
- def reset (self ):
93
+ def reset (self ) -> None :
92
94
"""Perform a soft-reset of the AHT"""
93
95
self ._buf [0 ] = AHTX0_CMD_SOFTRESET
94
96
with self .i2c_device as i2c :
95
97
i2c .write (self ._buf , start = 0 , end = 1 )
96
98
time .sleep (0.02 ) # 20ms delay to wake up
97
99
98
- def calibrate (self ):
100
+ def calibrate (self ) -> bool :
99
101
"""Ask the sensor to self-calibrate. Returns True on success, False otherwise"""
100
102
self ._buf [0 ] = AHTX0_CMD_CALIBRATE
101
103
self ._buf [1 ] = 0x08
@@ -109,26 +111,26 @@ def calibrate(self):
109
111
return True
110
112
111
113
@property
112
- def status (self ):
114
+ def status (self ) -> int :
113
115
"""The status byte initially returned from the sensor, see datasheet for details"""
114
116
with self .i2c_device as i2c :
115
117
i2c .readinto (self ._buf , start = 0 , end = 1 )
116
118
# print("status: "+hex(self._buf[0]))
117
119
return self ._buf [0 ]
118
120
119
121
@property
120
- def relative_humidity (self ):
122
+ def relative_humidity (self ) -> int :
121
123
"""The measured relative humidity in percent."""
122
124
self ._readdata ()
123
125
return self ._humidity
124
126
125
127
@property
126
- def temperature (self ):
128
+ def temperature (self ) -> int :
127
129
"""The measured temperature in degrees Celsius."""
128
130
self ._readdata ()
129
131
return self ._temp
130
132
131
- def _readdata (self ):
133
+ def _readdata (self ) -> None :
132
134
"""Internal function for triggering the AHT to read temp/humidity"""
133
135
self ._buf [0 ] = AHTX0_CMD_TRIGGER
134
136
self ._buf [1 ] = 0x33
0 commit comments