Skip to content

Commit 032c909

Browse files
authored
Merge pull request #20 from FoamyGuy/type_annotations
add type annotations
2 parents a5f7d31 + afea606 commit 032c909

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

adafruit_mprls.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
from digitalio import Direction
3939
from micropython import const
4040

41+
try:
42+
from typing import Optional
43+
from busio import I2C
44+
from digitalio import DigitalInOut # pylint: disable=ungrouped-imports
45+
except ImportError:
46+
pass
47+
4148
_MPRLS_DEFAULT_ADDR = const(0x18)
4249

4350

@@ -80,13 +87,13 @@ class MPRLS:
8087

8188
def __init__(
8289
self,
83-
i2c_bus,
90+
i2c_bus: I2C,
8491
*,
85-
addr=_MPRLS_DEFAULT_ADDR,
86-
reset_pin=None,
87-
eoc_pin=None,
88-
psi_min=0,
89-
psi_max=25
92+
addr: int = _MPRLS_DEFAULT_ADDR,
93+
reset_pin: Optional[DigitalInOut] = None,
94+
eoc_pin: Optional[DigitalInOut] = None,
95+
psi_min: int = 0,
96+
psi_max: int = 25
9097
):
9198
# Init I2C
9299
self._i2c = I2CDevice(i2c_bus, addr)
@@ -113,11 +120,11 @@ def __init__(
113120
# That's pretty much it, there's no ID register :(
114121

115122
@property
116-
def pressure(self):
123+
def pressure(self) -> float:
117124
"""The measured pressure, in hPa"""
118125
return self._read_data()
119126

120-
def _read_data(self):
127+
def _read_data(self) -> float:
121128
"""Read the status & 24-bit data reading"""
122129
self._buffer[0] = 0xAA
123130
self._buffer[1] = 0

0 commit comments

Comments
 (0)