From 7bb0efde2ccbb8a47de96fc3369479dcca8cf1c3 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 2 Dec 2024 16:14:38 -0600 Subject: [PATCH] type annotations --- adafruit_mpl115a2.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/adafruit_mpl115a2.py b/adafruit_mpl115a2.py index a8df94c..e5e574b 100644 --- a/adafruit_mpl115a2.py +++ b/adafruit_mpl115a2.py @@ -29,6 +29,14 @@ from adafruit_bus_device import i2c_device from micropython import const + +try: + from typing import Tuple + + from busio import I2C +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MPL115A2.git" @@ -41,22 +49,22 @@ class MPL115A2: """Driver for MPL115A2 I2C barometric pressure / temperature sensor.""" - def __init__(self, i2c, address=_MPL115A2_ADDRESS): + def __init__(self, i2c: I2C, address: int = _MPL115A2_ADDRESS): self._i2c = i2c_device.I2CDevice(i2c, address) self._buf = bytearray(4) self._read_coefficients() @property - def pressure(self): + def pressure(self) -> float: """The pressure in hPa.""" return self._read()[0] * 10 @property - def temperature(self): + def temperature(self) -> float: """The temperature in deg C.""" return self._read()[1] - def _read_coefficients(self): + def _read_coefficients(self) -> None: # pylint: disable=invalid-name buf = bytearray(8) buf[0] = _MPL115A2_REGISTER_A0_COEFF_MSB @@ -71,7 +79,7 @@ def _read_coefficients(self): self._b2 = b2 / 16384 self._c12 = c12 / 4194304 - def _read(self): + def _read(self) -> Tuple[float, float]: # pylint: disable=invalid-name self._buf[0] = _MPL115A2_REGISTER_STARTCONVERSION self._buf[1] = 0x00 # why? see datasheet, pg. 9, fig. 4