Skip to content

Commit 8054c02

Browse files
authored
Merge pull request #14 from FoamyGuy/type_annotations
type annotations
2 parents 523ca13 + 7bb0efd commit 8054c02

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

adafruit_mpl115a2.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
from adafruit_bus_device import i2c_device
3030
from micropython import const
3131

32+
33+
try:
34+
from typing import Tuple
35+
36+
from busio import I2C
37+
except ImportError:
38+
pass
39+
3240
__version__ = "0.0.0+auto.0"
3341
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MPL115A2.git"
3442

@@ -41,22 +49,22 @@
4149
class MPL115A2:
4250
"""Driver for MPL115A2 I2C barometric pressure / temperature sensor."""
4351

44-
def __init__(self, i2c, address=_MPL115A2_ADDRESS):
52+
def __init__(self, i2c: I2C, address: int = _MPL115A2_ADDRESS):
4553
self._i2c = i2c_device.I2CDevice(i2c, address)
4654
self._buf = bytearray(4)
4755
self._read_coefficients()
4856

4957
@property
50-
def pressure(self):
58+
def pressure(self) -> float:
5159
"""The pressure in hPa."""
5260
return self._read()[0] * 10
5361

5462
@property
55-
def temperature(self):
63+
def temperature(self) -> float:
5664
"""The temperature in deg C."""
5765
return self._read()[1]
5866

59-
def _read_coefficients(self):
67+
def _read_coefficients(self) -> None:
6068
# pylint: disable=invalid-name
6169
buf = bytearray(8)
6270
buf[0] = _MPL115A2_REGISTER_A0_COEFF_MSB
@@ -71,7 +79,7 @@ def _read_coefficients(self):
7179
self._b2 = b2 / 16384
7280
self._c12 = c12 / 4194304
7381

74-
def _read(self):
82+
def _read(self) -> Tuple[float, float]:
7583
# pylint: disable=invalid-name
7684
self._buf[0] = _MPL115A2_REGISTER_STARTCONVERSION
7785
self._buf[1] = 0x00 # why? see datasheet, pg. 9, fig. 4

0 commit comments

Comments
 (0)