Skip to content

add type annotations #20

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
Jan 2, 2025
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
23 changes: 15 additions & 8 deletions adafruit_mprls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
from digitalio import Direction
from micropython import const

try:
from typing import Optional
from busio import I2C
from digitalio import DigitalInOut # pylint: disable=ungrouped-imports
except ImportError:
pass

_MPRLS_DEFAULT_ADDR = const(0x18)


Expand Down Expand Up @@ -80,13 +87,13 @@ class MPRLS:

def __init__(
self,
i2c_bus,
i2c_bus: I2C,
*,
addr=_MPRLS_DEFAULT_ADDR,
reset_pin=None,
eoc_pin=None,
psi_min=0,
psi_max=25
addr: int = _MPRLS_DEFAULT_ADDR,
reset_pin: Optional[DigitalInOut] = None,
eoc_pin: Optional[DigitalInOut] = None,
psi_min: int = 0,
psi_max: int = 25
):
# Init I2C
self._i2c = I2CDevice(i2c_bus, addr)
Expand All @@ -113,11 +120,11 @@ def __init__(
# That's pretty much it, there's no ID register :(

@property
def pressure(self):
def pressure(self) -> float:
"""The measured pressure, in hPa"""
return self._read_data()

def _read_data(self):
def _read_data(self) -> float:
"""Read the status & 24-bit data reading"""
self._buffer[0] = 0xAA
self._buffer[1] = 0
Expand Down
Loading