Skip to content

Commit 153d0cf

Browse files
committed
fixed annotations
1 parent 1be1409 commit 153d0cf

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

adafruit_dymoscale.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
* Adafruit CircuitPython firmware for the supported boards:
2020
https://github.com/adafruit/circuitpython/releases
2121
"""
22-
22+
try:
23+
import typing
24+
except ImportError:
25+
pass
26+
2327
import time
2428
from pulseio import PulseIn
2529
from micropython import const
@@ -43,7 +47,7 @@ class ScaleReading:
4347
class DYMOScale:
4448
"""Interface to a DYMO postal scale."""
4549

46-
def __init__(self, data_pin, units_pin, timeout=1.0):
50+
def __init__(self, data_pin: pulseio.PulseIn, units_pin: digitalio.DigitalInOut, timeout: double =1.0) -> None:
4751
"""Sets up a DYMO postal scale.
4852
:param ~pulseio.PulseIn data_pin: The data pin from the Dymo scale.
4953
:param ~digitalio.DigitalInOut units_pin: The grams/oz button from the Dymo scale.
@@ -56,15 +60,15 @@ def __init__(self, data_pin, units_pin, timeout=1.0):
5660
self.dymo = PulseIn(data_pin, maxlen=96, idle_state=True)
5761

5862
@property
59-
def weight(self):
63+
def weight(self) -> ScaleReading:
6064
"""Weight in grams"""
6165
reading = self.get_scale_data()
6266
if reading.units == OUNCES:
6367
reading.weight *= 28.35
6468
reading.units = GRAMS
6569
return reading
6670

67-
def toggle_unit_button(self, switch_units=False):
71+
def toggle_unit_button(self, switch_units: bool =False) -> None:
6872
"""Toggles the unit button on the dymo.
6973
:param bool switch_units: Simulates pressing the units button.
7074
"""
@@ -78,7 +82,7 @@ def toggle_unit_button(self, switch_units=False):
7882
time.sleep(2)
7983
toggle_times += 1
8084

81-
def _read_pulse(self):
85+
def _read_pulse(self) -> None:
8286
"""Reads a pulse of SPI data on a pin that corresponds to DYMO scale
8387
output protocol (12 bytes of data at about 14KHz).
8488
"""
@@ -93,7 +97,7 @@ def _read_pulse(self):
9397
)
9498
self.dymo.pause()
9599

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

0 commit comments

Comments
 (0)