Skip to content

Commit

Permalink
add type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
FoamyGuy committed Dec 30, 2024
1 parent a5f7d31 commit afea606
Showing 1 changed file with 15 additions and 8 deletions.
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

0 comments on commit afea606

Please sign in to comment.