From 153d0cf03675189320f0e9b6e9080d12e13e65fc Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Wed, 29 Jun 2022 12:41:07 -0400 Subject: [PATCH 1/6] fixed annotations --- adafruit_dymoscale.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/adafruit_dymoscale.py b/adafruit_dymoscale.py index 6e9502b..2f0a738 100644 --- a/adafruit_dymoscale.py +++ b/adafruit_dymoscale.py @@ -19,7 +19,11 @@ * Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases """ - +try: + import typing +except ImportError: + pass + import time from pulseio import PulseIn from micropython import const @@ -43,7 +47,7 @@ class ScaleReading: class DYMOScale: """Interface to a DYMO postal scale.""" - def __init__(self, data_pin, units_pin, timeout=1.0): + def __init__(self, data_pin: pulseio.PulseIn, units_pin: digitalio.DigitalInOut, timeout: double =1.0) -> None: """Sets up a DYMO postal scale. :param ~pulseio.PulseIn data_pin: The data pin from the Dymo scale. :param ~digitalio.DigitalInOut units_pin: The grams/oz button from the Dymo scale. @@ -56,7 +60,7 @@ def __init__(self, data_pin, units_pin, timeout=1.0): self.dymo = PulseIn(data_pin, maxlen=96, idle_state=True) @property - def weight(self): + def weight(self) -> ScaleReading: """Weight in grams""" reading = self.get_scale_data() if reading.units == OUNCES: @@ -64,7 +68,7 @@ def weight(self): reading.units = GRAMS return reading - def toggle_unit_button(self, switch_units=False): + def toggle_unit_button(self, switch_units: bool =False) -> None: """Toggles the unit button on the dymo. :param bool switch_units: Simulates pressing the units button. """ @@ -78,7 +82,7 @@ def toggle_unit_button(self, switch_units=False): time.sleep(2) toggle_times += 1 - def _read_pulse(self): + def _read_pulse(self) -> None: """Reads a pulse of SPI data on a pin that corresponds to DYMO scale output protocol (12 bytes of data at about 14KHz). """ @@ -93,7 +97,7 @@ def _read_pulse(self): ) self.dymo.pause() - def get_scale_data(self): + def get_scale_data(self) -> ScaleReading: """Reads a pulse of SPI data and analyzes the resulting data.""" self._read_pulse() bits = [0] * 96 # there are 12 bytes = 96 bits of data From 3a276723834b0321756c4e270bcc745e2d7306c8 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Wed, 29 Jun 2022 15:11:42 -0400 Subject: [PATCH 2/6] updated annotations after pylint / black --- adafruit_dymoscale.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/adafruit_dymoscale.py b/adafruit_dymoscale.py index 2f0a738..ecf7484 100644 --- a/adafruit_dymoscale.py +++ b/adafruit_dymoscale.py @@ -23,7 +23,7 @@ import typing except ImportError: pass - + import time from pulseio import PulseIn from micropython import const @@ -47,7 +47,12 @@ class ScaleReading: class DYMOScale: """Interface to a DYMO postal scale.""" - def __init__(self, data_pin: pulseio.PulseIn, units_pin: digitalio.DigitalInOut, timeout: double =1.0) -> None: + def __init__( + self, + data_pin: pulseio.PulseIn, + units_pin: digitalio.DigitalInOut, + timeout: double = 1.0, + ) -> None: """Sets up a DYMO postal scale. :param ~pulseio.PulseIn data_pin: The data pin from the Dymo scale. :param ~digitalio.DigitalInOut units_pin: The grams/oz button from the Dymo scale. @@ -68,7 +73,7 @@ def weight(self) -> ScaleReading: reading.units = GRAMS return reading - def toggle_unit_button(self, switch_units: bool =False) -> None: + def toggle_unit_button(self, switch_units: bool = False) -> None: """Toggles the unit button on the dymo. :param bool switch_units: Simulates pressing the units button. """ From 0e1a961fbe49e87a21c768fee6158d0e238e442b Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Wed, 29 Jun 2022 20:15:37 -0400 Subject: [PATCH 3/6] updated annotations in error --- adafruit_dymoscale.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_dymoscale.py b/adafruit_dymoscale.py index ecf7484..7ff6fd4 100644 --- a/adafruit_dymoscale.py +++ b/adafruit_dymoscale.py @@ -21,6 +21,7 @@ """ try: import typing + import microcontroller except ImportError: pass @@ -49,9 +50,9 @@ class DYMOScale: def __init__( self, - data_pin: pulseio.PulseIn, - units_pin: digitalio.DigitalInOut, - timeout: double = 1.0, + data_pin: microcontroller.pin, + units_pin: microcontroller.pin, + timeout: float = 1.0, ) -> None: """Sets up a DYMO postal scale. :param ~pulseio.PulseIn data_pin: The data pin from the Dymo scale. From 6394511d960524902846b96d324d80eda37af926 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 30 Jun 2022 11:38:28 -0400 Subject: [PATCH 4/6] updated annotations --- adafruit_dymoscale.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/adafruit_dymoscale.py b/adafruit_dymoscale.py index 7ff6fd4..dba103b 100644 --- a/adafruit_dymoscale.py +++ b/adafruit_dymoscale.py @@ -19,11 +19,6 @@ * Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases """ -try: - import typing - import microcontroller -except ImportError: - pass import time from pulseio import PulseIn @@ -50,8 +45,8 @@ class DYMOScale: def __init__( self, - data_pin: microcontroller.pin, - units_pin: microcontroller.pin, + data_pin: int, + units_pin: int, timeout: float = 1.0, ) -> None: """Sets up a DYMO postal scale. From 0b4a2571cb1858f8fcd164b12c6c49eaebf68f76 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 30 Jun 2022 17:01:20 -0400 Subject: [PATCH 5/6] change pin datatypes to microcontroller.pin --- adafruit_dymoscale.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adafruit_dymoscale.py b/adafruit_dymoscale.py index dba103b..bae43f5 100644 --- a/adafruit_dymoscale.py +++ b/adafruit_dymoscale.py @@ -21,6 +21,7 @@ """ import time +import microcontroller from pulseio import PulseIn from micropython import const @@ -45,8 +46,8 @@ class DYMOScale: def __init__( self, - data_pin: int, - units_pin: int, + data_pin: microcontroller.pin, + units_pin: microcontroller.pin, timeout: float = 1.0, ) -> None: """Sets up a DYMO postal scale. From d5fefb0e483785fe56e96b642404028245c9d32c Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Fri, 1 Jul 2022 17:56:59 -0400 Subject: [PATCH 6/6] add conditional imports try/catch block and change pin definitions --- adafruit_dymoscale.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/adafruit_dymoscale.py b/adafruit_dymoscale.py index bae43f5..288eb39 100644 --- a/adafruit_dymoscale.py +++ b/adafruit_dymoscale.py @@ -20,8 +20,14 @@ https://github.com/adafruit/circuitpython/releases """ +try: + import typing # pylint: disable=unused-import + from digitalio import DigitalInOut + import microcontroller +except ImportError: + pass + import time -import microcontroller from pulseio import PulseIn from micropython import const @@ -46,8 +52,8 @@ class DYMOScale: def __init__( self, - data_pin: microcontroller.pin, - units_pin: microcontroller.pin, + data_pin: microcontroller.Pin, + units_pin: DigitalInOut, timeout: float = 1.0, ) -> None: """Sets up a DYMO postal scale.