Skip to content

Commit f083dfd

Browse files
authored
Merge pull request #20 from process1183/type_annotations
[#19] Add type annotations
2 parents 390426b + b1fcdd8 commit f083dfd

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

adafruit_pm25/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class PM25:
5050
5151
"""
5252

53-
def __init__(self):
53+
def __init__(self) -> None:
5454
# rad, ok make our internal buffer!
5555
self._buffer = bytearray(32)
5656
self.aqi_reading = {
@@ -68,11 +68,11 @@ def __init__(self):
6868
"particles 100um": None,
6969
}
7070

71-
def _read_into_buffer(self):
71+
def _read_into_buffer(self) -> None:
7272
"""Low level buffer filling function, to be overridden"""
7373
raise NotImplementedError()
7474

75-
def read(self):
75+
def read(self) -> dict:
7676
"""Read any available data from the air quality sensor and
7777
return a dictionary with available particulate/quality data"""
7878
self._read_into_buffer()

adafruit_pm25/i2c.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@
3535

3636
# imports
3737
import time
38-
from digitalio import Direction
38+
from digitalio import Direction, DigitalInOut
3939
from adafruit_bus_device.i2c_device import I2CDevice
4040
from . import PM25
4141

42+
try:
43+
# Used only for typing
44+
import typing # pylint: disable=unused-import
45+
from busio import I2C
46+
except ImportError:
47+
pass
48+
4249

4350
class PM25_I2C(PM25):
4451
"""
@@ -77,7 +84,9 @@ class PM25_I2C(PM25):
7784
7885
"""
7986

80-
def __init__(self, i2c_bus, reset_pin=None, address=0x12):
87+
def __init__(
88+
self, i2c_bus: I2C, reset_pin: DigitalInOut = None, address: int = 0x12
89+
) -> None:
8190
if reset_pin:
8291
# Reset device
8392
reset_pin.direction = Direction.OUTPUT
@@ -98,7 +107,7 @@ def __init__(self, i2c_bus, reset_pin=None, address=0x12):
98107
raise RuntimeError("Unable to find PM2.5 device")
99108
super().__init__()
100109

101-
def _read_into_buffer(self):
110+
def _read_into_buffer(self) -> None:
102111
with self.i2c_device as i2c:
103112
try:
104113
i2c.readinto(self._buffer)

adafruit_pm25/uart.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@
3030
"""
3131

3232
import time
33-
from digitalio import Direction
33+
from digitalio import Direction, DigitalInOut
3434
from . import PM25
3535

36+
try:
37+
# Used only for typing
38+
import typing # pylint: disable=unused-import
39+
from busio import UART
40+
except ImportError:
41+
pass
42+
3643

3744
class PM25_UART(PM25):
3845
"""
@@ -73,7 +80,7 @@ class PM25_UART(PM25):
7380
7481
"""
7582

76-
def __init__(self, uart, reset_pin=None):
83+
def __init__(self, uart: UART, reset_pin: DigitalInOut = None):
7784
if reset_pin:
7885
# Reset device
7986
reset_pin.direction = Direction.OUTPUT
@@ -86,7 +93,7 @@ def __init__(self, uart, reset_pin=None):
8693
self._uart = uart
8794
super().__init__()
8895

89-
def _read_into_buffer(self):
96+
def _read_into_buffer(self) -> None:
9097
while True:
9198
b = self._uart.read(1)
9299
if not b:

0 commit comments

Comments
 (0)