Skip to content

type annotations #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading