Skip to content

Commit 6561561

Browse files
authored
Merge pull request #10 from tcfranks/main
Correct Missing Type Annotations
2 parents 2d85ea5 + b4f5b86 commit 6561561

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

adafruit_sht4x.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
from adafruit_bus_device import i2c_device
3434
from micropython import const
3535

36+
try:
37+
from typing import Tuple
38+
from busio import I2C
39+
except ImportError:
40+
pass
41+
3642
__version__ = "0.0.0+auto.0"
3743
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SHT4x.git"
3844

@@ -46,7 +52,7 @@ class CV:
4652
"""struct helper"""
4753

4854
@classmethod
49-
def add_values(cls, value_tuples):
55+
def add_values(cls, value_tuples: Tuple[str, int, str, float]) -> None:
5056
"""Add CV values to the class"""
5157
cls.string = {}
5258
cls.delay = {}
@@ -58,7 +64,7 @@ def add_values(cls, value_tuples):
5864
cls.delay[value] = delay
5965

6066
@classmethod
61-
def is_valid(cls, value):
67+
def is_valid(cls, value: int) -> bool:
6268
"""Validate that a given value is a member"""
6369
return value in cls.string
6470

@@ -126,14 +132,14 @@ class SHT4x:
126132
127133
"""
128134

129-
def __init__(self, i2c_bus, address=_SHT4X_DEFAULT_ADDR):
135+
def __init__(self, i2c_bus: I2C, address: int = _SHT4X_DEFAULT_ADDR) -> None:
130136
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
131137
self._buffer = bytearray(6)
132138
self.reset()
133139
self._mode = Mode.NOHEAT_HIGHPRECISION # pylint: disable=no-member
134140

135141
@property
136-
def serial_number(self):
142+
def serial_number(self) -> int:
137143
"""The unique 32-bit serial number"""
138144
self._buffer[0] = _SHT4X_READSERIAL
139145
with self.i2c_device as i2c:
@@ -153,37 +159,37 @@ def serial_number(self):
153159
serial = (ser1[0] << 24) + (ser1[1] << 16) + (ser2[0] << 8) + ser2[1]
154160
return serial
155161

156-
def reset(self):
162+
def reset(self) -> None:
157163
"""Perform a soft reset of the sensor, resetting all settings to their power-on defaults"""
158164
self._buffer[0] = _SHT4X_SOFTRESET
159165
with self.i2c_device as i2c:
160166
i2c.write(self._buffer, end=1)
161167
time.sleep(0.001)
162168

163169
@property
164-
def mode(self):
170+
def mode(self) -> int:
165171
"""The current sensor reading mode (heater and precision)"""
166172
return self._mode
167173

168174
@mode.setter
169-
def mode(self, new_mode):
175+
def mode(self, new_mode: int) -> None:
170176

171177
if not Mode.is_valid(new_mode):
172178
raise AttributeError("mode must be a Mode")
173179
self._mode = new_mode
174180

175181
@property
176-
def relative_humidity(self):
182+
def relative_humidity(self) -> float:
177183
"""The current relative humidity in % rH. This is a value from 0-100%."""
178184
return self.measurements[1]
179185

180186
@property
181-
def temperature(self):
187+
def temperature(self) -> float:
182188
"""The current temperature in degrees Celsius"""
183189
return self.measurements[0]
184190

185191
@property
186-
def measurements(self):
192+
def measurements(self) -> Tuple[float, float]:
187193
"""both `temperature` and `relative_humidity`, read simultaneously"""
188194

189195
temperature = None
@@ -226,7 +232,7 @@ def measurements(self):
226232
# Test data [0xBE, 0xEF] should yield 0x92
227233

228234
@staticmethod
229-
def _crc8(buffer):
235+
def _crc8(buffer) -> int:
230236
"""verify the crc8 checksum"""
231237
crc = 0xFF
232238
for byte in buffer:

0 commit comments

Comments
 (0)