Skip to content

Commit b7c0de0

Browse files
authored
Merge pull request #13 from tcfranks/main
Annotations fix
2 parents 1be1409 + d5fefb0 commit b7c0de0

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

adafruit_dymoscale.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
https://github.com/adafruit/circuitpython/releases
2121
"""
2222

23+
try:
24+
import typing # pylint: disable=unused-import
25+
from digitalio import DigitalInOut
26+
import microcontroller
27+
except ImportError:
28+
pass
29+
2330
import time
2431
from pulseio import PulseIn
2532
from micropython import const
@@ -43,7 +50,12 @@ class ScaleReading:
4350
class DYMOScale:
4451
"""Interface to a DYMO postal scale."""
4552

46-
def __init__(self, data_pin, units_pin, timeout=1.0):
53+
def __init__(
54+
self,
55+
data_pin: microcontroller.Pin,
56+
units_pin: DigitalInOut,
57+
timeout: float = 1.0,
58+
) -> None:
4759
"""Sets up a DYMO postal scale.
4860
:param ~pulseio.PulseIn data_pin: The data pin from the Dymo scale.
4961
:param ~digitalio.DigitalInOut units_pin: The grams/oz button from the Dymo scale.
@@ -56,15 +68,15 @@ def __init__(self, data_pin, units_pin, timeout=1.0):
5668
self.dymo = PulseIn(data_pin, maxlen=96, idle_state=True)
5769

5870
@property
59-
def weight(self):
71+
def weight(self) -> ScaleReading:
6072
"""Weight in grams"""
6173
reading = self.get_scale_data()
6274
if reading.units == OUNCES:
6375
reading.weight *= 28.35
6476
reading.units = GRAMS
6577
return reading
6678

67-
def toggle_unit_button(self, switch_units=False):
79+
def toggle_unit_button(self, switch_units: bool = False) -> None:
6880
"""Toggles the unit button on the dymo.
6981
:param bool switch_units: Simulates pressing the units button.
7082
"""
@@ -78,7 +90,7 @@ def toggle_unit_button(self, switch_units=False):
7890
time.sleep(2)
7991
toggle_times += 1
8092

81-
def _read_pulse(self):
93+
def _read_pulse(self) -> None:
8294
"""Reads a pulse of SPI data on a pin that corresponds to DYMO scale
8395
output protocol (12 bytes of data at about 14KHz).
8496
"""
@@ -93,7 +105,7 @@ def _read_pulse(self):
93105
)
94106
self.dymo.pause()
95107

96-
def get_scale_data(self):
108+
def get_scale_data(self) -> ScaleReading:
97109
"""Reads a pulse of SPI data and analyzes the resulting data."""
98110
self._read_pulse()
99111
bits = [0] * 96 # there are 12 bytes = 96 bits of data

0 commit comments

Comments
 (0)