Skip to content

Commit

Permalink
Merge pull request #14 from FoamyGuy/type_annotations
Browse files Browse the repository at this point in the history
type annotations
  • Loading branch information
FoamyGuy authored Dec 4, 2024
2 parents 523ca13 + 7bb0efd commit 8054c02
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions adafruit_mpl115a2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8054c02

Please sign in to comment.