Skip to content

Commit 236b313

Browse files
committed
Add missing type annotations
1 parent 71177d0 commit 236b313

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

adafruit_lps35hw.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
from adafruit_register.i2c_bits import RWBits, ROBits
5858
from adafruit_register.i2c_bit import RWBit
5959

60+
try:
61+
import typing # pylint: disable=unused-import
62+
from busio import I2C
63+
except ImportError:
64+
pass
65+
6066
_INTERRUPT_CFG = const(0x0B)
6167
_THS_P_L = const(0x0C)
6268
_THS_P_H = const(0x0D)
@@ -187,11 +193,10 @@ class LPS35HW: # pylint: disable=too-many-instance-attributes
187193
_chip_id = UnaryStruct(_WHO_AM_I, "<B")
188194
_pressure_threshold = UnaryStruct(_THS_P_L, "<H")
189195

190-
def __init__(self, i2c_bus, address=0x5D):
196+
def __init__(self, i2c_bus: I2C, address: int = 0x5D) -> None:
191197
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)
192198
if self._chip_id != 0xB1:
193-
raise RuntimeError("Failed to find LPS35HW! Chip ID 0x%x" % self._chip_id)
194-
199+
raise RuntimeError(f"Failed to find LPS35HW! Chip ID {self._chip_id:#x}")
195200
self.reset()
196201

197202
# set data_rate to put the sensor in continuous mode
@@ -201,7 +206,7 @@ def __init__(self, i2c_bus, address=0x5D):
201206
self._interrupt_latch = True
202207

203208
@property
204-
def pressure(self):
209+
def pressure(self) -> float:
205210
"""The current pressure measurement in hPa"""
206211
# reset the filter to prevent spurious readings
207212
self._reset_filter # pylint: disable=pointless-statement
@@ -213,58 +218,58 @@ def pressure(self):
213218
return raw / 4096.0
214219

215220
@property
216-
def temperature(self):
221+
def temperature(self) -> float:
217222
"""The current temperature measurement in degrees Celsius"""
218223
return self._raw_temperature / 100.0
219224

220-
def reset(self):
225+
def reset(self) -> None:
221226
"""Reset the sensor, restoring all configuration registers to their defaults"""
222227
self._reset = True
223228
# wait for the reset to finish
224229
while self._reset:
225230
pass
226231

227-
def take_measurement(self):
232+
def take_measurement(self) -> None:
228233
"""Update the value of :attr:`pressure` and :attr:`temperature`
229234
by taking a single measurement. Only meaningful if ``data_rate``
230235
is set to ``ONE_SHOT``"""
231236
self._one_shot = True
232237
while self._one_shot:
233238
pass
234239

235-
def zero_pressure(self):
240+
def zero_pressure(self) -> None:
236241
"""Set the current pressure as zero and report the :attr:`pressure` relative to it"""
237242
self._auto_zero = True
238243
while self._auto_zero:
239244
pass
240245

241-
def reset_pressure(self):
246+
def reset_pressure(self) -> None:
242247
"""Reset :attr:`pressure` to be reported as the measured absolute value"""
243248
self._reset_zero = True
244249

245250
@property
246-
def pressure_threshold(self):
251+
def pressure_threshold(self) -> float:
247252
"""The high pressure threshold. Use :attr:`high_threshold_enabled`
248253
or :attr:`high_threshold_enabled` to use it"""
249254
return self._pressure_threshold / 16
250255

251256
@pressure_threshold.setter
252-
def pressure_threshold(self, value):
257+
def pressure_threshold(self, value: float) -> None:
253258
"""The high value threshold"""
254259
self._pressure_threshold = value * 16
255260

256261
@property
257-
def high_threshold_enabled(self):
262+
def high_threshold_enabled(self) -> bool:
258263
"""Set to `True` or `False` to enable or disable the high pressure threshold"""
259264
return self._interrupts_enabled and self._interrupt_high
260265

261266
@high_threshold_enabled.setter
262-
def high_threshold_enabled(self, value):
267+
def high_threshold_enabled(self, value: bool) -> None:
263268
self._interrupts_enabled = value
264269
self._interrupt_high = value
265270

266271
@property
267-
def low_threshold_enabled(self):
272+
def low_threshold_enabled(self) -> bool:
268273
"""Set to `True` or `False` to enable or disable the low pressure threshold.
269274
270275
.. note::
@@ -274,19 +279,19 @@ def low_threshold_enabled(self):
274279
return self._interrupts_enabled and self._interrupt_low
275280

276281
@low_threshold_enabled.setter
277-
def low_threshold_enabled(self, value):
282+
def low_threshold_enabled(self, value: bool) -> None:
278283
self._interrupts_enabled = value
279284
self._interrupt_low = value
280285

281286
@property
282-
def high_threshold_exceeded(self):
287+
def high_threshold_exceeded(self) -> bool:
283288
"""Returns `True` if the pressure high threshold has been exceeded.
284289
Must be enabled by setting :attr:`high_threshold_enabled` to `True`
285290
and setting a :attr:`pressure_threshold`."""
286291
return self._pressure_high
287292

288293
@property
289-
def low_threshold_exceeded(self):
294+
def low_threshold_exceeded(self) -> bool:
290295
"""Returns `True` if the pressure low threshold has been exceeded.
291296
Must be enabled by setting :attr:`high_threshold_enabled`
292297
to `True` and setting a :attr:`pressure_threshold`."""

0 commit comments

Comments
 (0)