From 87a3722f053acddccb55b10833fa9eb3c1bf5851 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Thu, 11 Nov 2021 10:38:48 -0500 Subject: [PATCH 1/9] Add type hints --- adafruit_funhouse/graphics.py | 2 +- adafruit_funhouse/network.py | 46 ++++++++++++++++++-------------- adafruit_funhouse/peripherals.py | 4 +-- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/adafruit_funhouse/graphics.py b/adafruit_funhouse/graphics.py index a44716f..7762631 100755 --- a/adafruit_funhouse/graphics.py +++ b/adafruit_funhouse/graphics.py @@ -45,7 +45,7 @@ class Graphics(GraphicsBase): """ # pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements, too-few-public-methods - def __init__(self, *, default_bg=0, rotation=270, scale=1, debug=False): + def __init__(self, *, default_bg: int = 0, rotation: int = 270, scale: int = 1, debug: bool = False): self._debug = debug self.display = board.DISPLAY self.display.rotation = rotation diff --git a/adafruit_funhouse/network.py b/adafruit_funhouse/network.py index d97100e..09b10d0 100755 --- a/adafruit_funhouse/network.py +++ b/adafruit_funhouse/network.py @@ -33,6 +33,12 @@ from adafruit_portalbase.network import NetworkBase from adafruit_portalbase.wifi_esp32s2 import WiFi +try: + from typing import Optional, Union + from adafruit_dotstar import DotStar +except ImportError: + pass + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse.git" @@ -54,9 +60,9 @@ class Network(NetworkBase): def __init__( self, *, - status_dotstar=None, - extract_values=True, - debug=False, + status_dotstar: Optional[DotStar] = None, + extract_values: bool = True, + debug: bool = False, ): super().__init__( WiFi(status_led=status_dotstar), @@ -65,7 +71,7 @@ def __init__( ) self._mqtt_client = None - def init_io_mqtt(self): + def init_io_mqtt(self) -> IO_MQTT: """Initialize MQTT for Adafruit IO""" try: aio_username = self._secrets["aio_username"] @@ -80,12 +86,12 @@ def init_io_mqtt(self): # pylint: disable=too-many-arguments def init_mqtt( self, - broker, - port=8883, - username=None, - password=None, - use_io=False, - ): + broker: str, + port: int = 8883, + username: str = None, + password: str = None, + use_io: bool = False, + ) -> Union[MQTT, IO_MQTT]: """Initialize MQTT""" self.connect() self._mqtt_client = MQTT.MQTT( @@ -103,12 +109,12 @@ def init_mqtt( # pylint: enable=too-many-arguments - def _get_mqtt_client(self): + def _get_mqtt_client(self) -> Union[MQTT, IO_MQTT]: if self._mqtt_client is not None: return self._mqtt_client raise RuntimeError("Please initialize MQTT before using") - def mqtt_loop(self, *args, suppress_mqtt_errors=True, **kwargs): + def mqtt_loop(self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int): """Run the MQTT Loop""" self._get_mqtt_client() if suppress_mqtt_errors: @@ -123,7 +129,7 @@ def mqtt_loop(self, *args, suppress_mqtt_errors=True, **kwargs): if self._mqtt_client is not None: self._mqtt_client.loop(*args, **kwargs) - def mqtt_publish(self, *args, suppress_mqtt_errors=True, **kwargs): + def mqtt_publish(self, *args: Union[str, int, float], suppress_mqtt_errors: bool = True, **kwargs: Union[str, int, float]): """Publish to MQTT""" self._get_mqtt_client() if suppress_mqtt_errors: @@ -136,7 +142,7 @@ def mqtt_publish(self, *args, suppress_mqtt_errors=True, **kwargs): if self._mqtt_client is not None: self._mqtt_client.publish(*args, **kwargs) - def mqtt_connect(self, *args, **kwargs): + def mqtt_connect(self, *args: Union[bool, str, int], **kwargs: Union[bool, str, int]): """Connect to MQTT""" self._get_mqtt_client() if self._mqtt_client is not None: @@ -153,7 +159,7 @@ def on_mqtt_connect(self): return None @on_mqtt_connect.setter - def on_mqtt_connect(self, value): + def on_mqtt_connect(self, value: function): self._get_mqtt_client() self._mqtt_client.on_connect = value @@ -168,7 +174,7 @@ def on_mqtt_disconnect(self): return None @on_mqtt_disconnect.setter - def on_mqtt_disconnect(self, value): + def on_mqtt_disconnect(self, value: function): self._get_mqtt_client().on_disconnect = value @property @@ -182,7 +188,7 @@ def on_mqtt_subscribe(self): return None @on_mqtt_subscribe.setter - def on_mqtt_subscribe(self, value): + def on_mqtt_subscribe(self, value: function): self._get_mqtt_client().on_subscribe = value @property @@ -196,7 +202,7 @@ def on_mqtt_unsubscribe(self): return None @on_mqtt_unsubscribe.setter - def on_mqtt_unsubscribe(self, value): + def on_mqtt_unsubscribe(self, value: function): self._get_mqtt_client().on_unsubscribe = value @property @@ -210,7 +216,7 @@ def on_mqtt_message(self): return None @on_mqtt_message.setter - def on_mqtt_message(self, value): + def on_mqtt_message(self, value: function): self._get_mqtt_client().on_message = value @property @@ -222,5 +228,5 @@ def enabled(self): return self._wifi.enabled @enabled.setter - def enabled(self, value): + def enabled(self, value: bool): self._wifi.enabled = bool(value) diff --git a/adafruit_funhouse/peripherals.py b/adafruit_funhouse/peripherals.py index 3ea876a..87850ed 100755 --- a/adafruit_funhouse/peripherals.py +++ b/adafruit_funhouse/peripherals.py @@ -108,7 +108,7 @@ def play_tone(frequency, duration): pass attempt += 1 - def set_dotstars(self, *values): + def set_dotstars(self, *values: int): """Set the dotstar values to the provided values""" for i, value in enumerate(values[: len(self.dotstars)]): self.dotstars[i] = value @@ -234,7 +234,7 @@ def led(self): return self._led.value @led.setter - def led(self, value): + def led(self, value: bool): self._led.value = bool(value) @property From b99b6f68731e7d1bb99201c4bc209046cf68a176 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Thu, 11 Nov 2021 10:40:38 -0500 Subject: [PATCH 2/9] Reformatted per pre-commit --- adafruit_funhouse/graphics.py | 9 ++++++++- adafruit_funhouse/network.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/adafruit_funhouse/graphics.py b/adafruit_funhouse/graphics.py index 7762631..c5f6e0c 100755 --- a/adafruit_funhouse/graphics.py +++ b/adafruit_funhouse/graphics.py @@ -45,7 +45,14 @@ class Graphics(GraphicsBase): """ # pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements, too-few-public-methods - def __init__(self, *, default_bg: int = 0, rotation: int = 270, scale: int = 1, debug: bool = False): + def __init__( + self, + *, + default_bg: int = 0, + rotation: int = 270, + scale: int = 1, + debug: bool = False + ): self._debug = debug self.display = board.DISPLAY self.display.rotation = rotation diff --git a/adafruit_funhouse/network.py b/adafruit_funhouse/network.py index 09b10d0..60c4a37 100755 --- a/adafruit_funhouse/network.py +++ b/adafruit_funhouse/network.py @@ -129,7 +129,12 @@ def mqtt_loop(self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int if self._mqtt_client is not None: self._mqtt_client.loop(*args, **kwargs) - def mqtt_publish(self, *args: Union[str, int, float], suppress_mqtt_errors: bool = True, **kwargs: Union[str, int, float]): + def mqtt_publish( + self, + *args: Union[str, int, float], + suppress_mqtt_errors: bool = True, + **kwargs: Union[str, int, float] + ): """Publish to MQTT""" self._get_mqtt_client() if suppress_mqtt_errors: @@ -142,7 +147,9 @@ def mqtt_publish(self, *args: Union[str, int, float], suppress_mqtt_errors: bool if self._mqtt_client is not None: self._mqtt_client.publish(*args, **kwargs) - def mqtt_connect(self, *args: Union[bool, str, int], **kwargs: Union[bool, str, int]): + def mqtt_connect( + self, *args: Union[bool, str, int], **kwargs: Union[bool, str, int] + ): """Connect to MQTT""" self._get_mqtt_client() if self._mqtt_client is not None: From 747b4cd3faa1992e3e997ae5a794beaf20ea63ae Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Thu, 11 Nov 2021 10:47:15 -0500 Subject: [PATCH 3/9] Correct type "function" to Callable --- adafruit_funhouse/network.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/adafruit_funhouse/network.py b/adafruit_funhouse/network.py index 60c4a37..90216ee 100755 --- a/adafruit_funhouse/network.py +++ b/adafruit_funhouse/network.py @@ -34,7 +34,7 @@ from adafruit_portalbase.wifi_esp32s2 import WiFi try: - from typing import Optional, Union + from typing import Optional, Union, Callable from adafruit_dotstar import DotStar except ImportError: pass @@ -166,7 +166,7 @@ def on_mqtt_connect(self): return None @on_mqtt_connect.setter - def on_mqtt_connect(self, value: function): + def on_mqtt_connect(self, value: Callable): self._get_mqtt_client() self._mqtt_client.on_connect = value @@ -181,7 +181,7 @@ def on_mqtt_disconnect(self): return None @on_mqtt_disconnect.setter - def on_mqtt_disconnect(self, value: function): + def on_mqtt_disconnect(self, value: Callable): self._get_mqtt_client().on_disconnect = value @property @@ -195,7 +195,7 @@ def on_mqtt_subscribe(self): return None @on_mqtt_subscribe.setter - def on_mqtt_subscribe(self, value: function): + def on_mqtt_subscribe(self, value: Callable): self._get_mqtt_client().on_subscribe = value @property @@ -209,7 +209,7 @@ def on_mqtt_unsubscribe(self): return None @on_mqtt_unsubscribe.setter - def on_mqtt_unsubscribe(self, value: function): + def on_mqtt_unsubscribe(self, value: Callable): self._get_mqtt_client().on_unsubscribe = value @property @@ -223,7 +223,7 @@ def on_mqtt_message(self): return None @on_mqtt_message.setter - def on_mqtt_message(self, value: function): + def on_mqtt_message(self, value: Callable): self._get_mqtt_client().on_message = value @property From 5515c91aa4217d97c204b9e803777c421d78fe2f Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Thu, 11 Nov 2021 10:47:46 -0500 Subject: [PATCH 4/9] Correct typing for MQTT to be "MQTT.MQTT" MQTT alone references the module as imported --- adafruit_funhouse/network.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_funhouse/network.py b/adafruit_funhouse/network.py index 90216ee..fe52501 100755 --- a/adafruit_funhouse/network.py +++ b/adafruit_funhouse/network.py @@ -91,7 +91,7 @@ def init_mqtt( username: str = None, password: str = None, use_io: bool = False, - ) -> Union[MQTT, IO_MQTT]: + ) -> Union[MQTT.MQTT, IO_MQTT]: """Initialize MQTT""" self.connect() self._mqtt_client = MQTT.MQTT( @@ -109,7 +109,7 @@ def init_mqtt( # pylint: enable=too-many-arguments - def _get_mqtt_client(self) -> Union[MQTT, IO_MQTT]: + def _get_mqtt_client(self) -> Union[MQTT.MQTT, IO_MQTT]: if self._mqtt_client is not None: return self._mqtt_client raise RuntimeError("Please initialize MQTT before using") From 5969636f2a44941327401ae1c54d004d69c1d788 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Fri, 12 Nov 2021 10:30:11 -0500 Subject: [PATCH 5/9] Added missing typehints --- adafruit_funhouse/__init__.py | 30 ++++++++++++++---------- adafruit_funhouse/graphics.py | 2 +- adafruit_funhouse/network.py | 32 +++++++++++++------------- adafruit_funhouse/peripherals.py | 39 ++++++++++++++++---------------- 4 files changed, 55 insertions(+), 48 deletions(-) diff --git a/adafruit_funhouse/__init__.py b/adafruit_funhouse/__init__.py index d237d98..8830bf1 100755 --- a/adafruit_funhouse/__init__.py +++ b/adafruit_funhouse/__init__.py @@ -34,6 +34,12 @@ from adafruit_funhouse.graphics import Graphics from adafruit_funhouse.peripherals import Peripherals +try: + from typing import Optional, Dict, Union, Callable, Sequence, List + from adafruit_dotstar import DotStar +except ImportError: + pass + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse.git" @@ -65,17 +71,17 @@ class FunHouse(PortalBase): def __init__( self, *, - url=None, - headers=None, - json_path=None, - regexp_path=None, - default_bg=0, - status_dotstar=None, - json_transform=None, - rotation=270, - scale=1, - debug=False, - ): + url: Optional[str] = None, + headers: Dict[str, str] = None, + json_path: Optional[Union[List[str], List[List[str]]]] = None, + regexp_path: Optional[Sequence[str]] = None, + default_bg: int = 0, + status_dotstar: Optional[DotStar] = None, + json_transform: Optional[Union[Callable, List[Callable]]] = None, + rotation: int = 270, + scale: int = 1, + debug: bool = False, + ) -> None: network = Network( status_dotstar=status_dotstar, @@ -105,7 +111,7 @@ def __init__( gc.collect() - def enter_light_sleep(self, sleep_time): + def enter_light_sleep(self, sleep_time: float) -> None: """ Enter light sleep and resume the program after a certain period of time. diff --git a/adafruit_funhouse/graphics.py b/adafruit_funhouse/graphics.py index c5f6e0c..24ea359 100755 --- a/adafruit_funhouse/graphics.py +++ b/adafruit_funhouse/graphics.py @@ -52,7 +52,7 @@ def __init__( rotation: int = 270, scale: int = 1, debug: bool = False - ): + ) -> None: self._debug = debug self.display = board.DISPLAY self.display.rotation = rotation diff --git a/adafruit_funhouse/network.py b/adafruit_funhouse/network.py index fe52501..51e11c5 100755 --- a/adafruit_funhouse/network.py +++ b/adafruit_funhouse/network.py @@ -63,7 +63,7 @@ def __init__( status_dotstar: Optional[DotStar] = None, extract_values: bool = True, debug: bool = False, - ): + ) -> None: super().__init__( WiFi(status_led=status_dotstar), extract_values=extract_values, @@ -114,7 +114,7 @@ def _get_mqtt_client(self) -> Union[MQTT.MQTT, IO_MQTT]: return self._mqtt_client raise RuntimeError("Please initialize MQTT before using") - def mqtt_loop(self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int): + def mqtt_loop(self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int) -> None: """Run the MQTT Loop""" self._get_mqtt_client() if suppress_mqtt_errors: @@ -134,7 +134,7 @@ def mqtt_publish( *args: Union[str, int, float], suppress_mqtt_errors: bool = True, **kwargs: Union[str, int, float] - ): + ) -> None: """Publish to MQTT""" self._get_mqtt_client() if suppress_mqtt_errors: @@ -149,14 +149,14 @@ def mqtt_publish( def mqtt_connect( self, *args: Union[bool, str, int], **kwargs: Union[bool, str, int] - ): + ) -> None: """Connect to MQTT""" self._get_mqtt_client() if self._mqtt_client is not None: self._mqtt_client.connect(*args, **kwargs) @property - def on_mqtt_connect(self): + def on_mqtt_connect(self) -> Optional[Callable]: """ Get or Set the MQTT Connect Handler @@ -166,12 +166,12 @@ def on_mqtt_connect(self): return None @on_mqtt_connect.setter - def on_mqtt_connect(self, value: Callable): + def on_mqtt_connect(self, value: Callable) -> None: self._get_mqtt_client() self._mqtt_client.on_connect = value @property - def on_mqtt_disconnect(self): + def on_mqtt_disconnect(self) -> Optional[Callable]: """ Get or Set the MQTT Disconnect Handler @@ -181,11 +181,11 @@ def on_mqtt_disconnect(self): return None @on_mqtt_disconnect.setter - def on_mqtt_disconnect(self, value: Callable): + def on_mqtt_disconnect(self, value: Callable) -> None: self._get_mqtt_client().on_disconnect = value @property - def on_mqtt_subscribe(self): + def on_mqtt_subscribe(self) -> Optional[Callable]: """ Get or Set the MQTT Subscribe Handler @@ -195,11 +195,11 @@ def on_mqtt_subscribe(self): return None @on_mqtt_subscribe.setter - def on_mqtt_subscribe(self, value: Callable): + def on_mqtt_subscribe(self, value: Callable) -> None: self._get_mqtt_client().on_subscribe = value @property - def on_mqtt_unsubscribe(self): + def on_mqtt_unsubscribe(self) -> Optional[Callable]: """ Get or Set the MQTT Unsubscribe Handler @@ -209,11 +209,11 @@ def on_mqtt_unsubscribe(self): return None @on_mqtt_unsubscribe.setter - def on_mqtt_unsubscribe(self, value: Callable): + def on_mqtt_unsubscribe(self, value: Callable) -> None: self._get_mqtt_client().on_unsubscribe = value @property - def on_mqtt_message(self): + def on_mqtt_message(self) -> Optional[Callable]: """ Get or Set the MQTT Message Handler @@ -223,11 +223,11 @@ def on_mqtt_message(self): return None @on_mqtt_message.setter - def on_mqtt_message(self, value: Callable): + def on_mqtt_message(self, value: Callable) -> None: self._get_mqtt_client().on_message = value @property - def enabled(self): + def enabled(self) -> bool: """ Get or Set whether the WiFi is enabled @@ -235,5 +235,5 @@ def enabled(self): return self._wifi.enabled @enabled.setter - def enabled(self, value: bool): + def enabled(self, value: bool) -> None: self._wifi.enabled = bool(value) diff --git a/adafruit_funhouse/peripherals.py b/adafruit_funhouse/peripherals.py index 87850ed..5ff36ae 100755 --- a/adafruit_funhouse/peripherals.py +++ b/adafruit_funhouse/peripherals.py @@ -27,6 +27,7 @@ """ +from typing import Optional import board from digitalio import DigitalInOut, Direction, Pull from analogio import AnalogIn @@ -44,7 +45,7 @@ class Peripherals: """Peripherals Helper Class for the FunHouse Library""" # pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements - def __init__(self): + def __init__(self) -> None: # Dotstars self.dotstars = adafruit_dotstar.DotStar( board.DOTSTAR_CLOCK, board.DOTSTAR_DATA, 5, brightness=0.3 @@ -90,7 +91,7 @@ def __init__(self): self._pir.direction = Direction.INPUT @staticmethod - def play_tone(frequency, duration): + def play_tone(frequency: float, duration: float) -> None: """Automatically Enable/Disable the speaker and play a tone at the specified frequency for the specified duration It will attempt to play the sound up to 3 times in the case of @@ -108,12 +109,12 @@ def play_tone(frequency, duration): pass attempt += 1 - def set_dotstars(self, *values: int): + def set_dotstars(self, *values: int) -> None: """Set the dotstar values to the provided values""" for i, value in enumerate(values[: len(self.dotstars)]): self.dotstars[i] = value - def deinit(self): + def deinit(self) -> None: """Call deinit on all resources to free them""" self.dotstars.deinit() for button in self._buttons: @@ -125,56 +126,56 @@ def deinit(self): self._pir.deinit() @property - def button_down(self): + def button_down(self) -> bool: """ Return whether Down Button is pressed """ return self._buttons[0].value @property - def button_sel(self): + def button_sel(self) -> bool: """ Return whether Sel Button is pressed """ return self._buttons[1].value @property - def button_up(self): + def button_up(self) -> bool: """ Return whether Up Button is pressed """ return self._buttons[2].value @property - def any_button_pressed(self): + def any_button_pressed(self) -> bool: """ Return whether any button is pressed """ return True in [button.value for button in enumerate(self._buttons)] @property - def captouch6(self): + def captouch6(self) -> bool: """ Return whether CT6 Touch Pad is touched """ return self._ctp[0].value @property - def captouch7(self): + def captouch7(self) -> bool: """ Return whether CT7 Touch Pad is touched """ return self._ctp[1].value @property - def captouch8(self): + def captouch8(self) -> bool: """ Return whether CT8 Touch Pad is touched """ return self._ctp[2].value @property - def slider(self): + def slider(self) -> Optional[float]: """ Return the slider position value in the range of 0.0-1.0 or None if not touched """ @@ -186,7 +187,7 @@ def slider(self): return cap_map.index(val) / 8 if val in cap_map else None @property - def light(self): + def light(self) -> int: """ Return the value of the light sensor. The neopixel_disable property must be false to get a value. @@ -206,39 +207,39 @@ def light(self): return self._light.value @property - def temperature(self): + def temperature(self) -> float: """ Return the temperature in degrees Celsius """ return self._aht20.temperature @property - def relative_humidity(self): + def relative_humidity(self) -> float: """ Return the relative humidity as a percentage (0 - 100) """ return self._aht20.relative_humidity @property - def pressure(self): + def pressure(self) -> float: """ Return the barometric pressure in hPa, or equivalently in mBar """ return self._dps310.pressure @property - def led(self): + def led(self) -> bool: """ Return or set the value of the LED """ return self._led.value @led.setter - def led(self, value: bool): + def led(self, value: bool) -> None: self._led.value = bool(value) @property - def pir_sensor(self): + def pir_sensor(self) -> bool: """ Return the value of the PIR Sensor """ From fe581f02a17d57bf8087c04205bef9f88e3ace97 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Fri, 12 Nov 2021 10:32:59 -0500 Subject: [PATCH 6/9] Formatted per pre-commit --- adafruit_funhouse/network.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_funhouse/network.py b/adafruit_funhouse/network.py index 51e11c5..5ad14c9 100755 --- a/adafruit_funhouse/network.py +++ b/adafruit_funhouse/network.py @@ -114,7 +114,9 @@ def _get_mqtt_client(self) -> Union[MQTT.MQTT, IO_MQTT]: return self._mqtt_client raise RuntimeError("Please initialize MQTT before using") - def mqtt_loop(self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int) -> None: + def mqtt_loop( + self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int + ) -> None: """Run the MQTT Loop""" self._get_mqtt_client() if suppress_mqtt_errors: From 14e1723730b913177abdab23797f085c11b514db Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Fri, 12 Nov 2021 10:57:12 -0500 Subject: [PATCH 7/9] Disable duplicate-code for pylint Failed during pylint check --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1b9fadc..43d1385 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: name: pylint (library code) types: [python] args: - - --disable=consider-using-f-string + - --disable=consider-using-f-string,duplicate-code exclude: "^(docs/|examples/|tests/|setup.py$)" - id: pylint name: pylint (example code) From 2980950d7683e3a5a3a2e925871df9fa245a1448 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sat, 13 Nov 2021 22:19:55 -0500 Subject: [PATCH 8/9] Changes per review --- .pre-commit-config.yaml | 2 +- adafruit_funhouse/__init__.py | 2 +- adafruit_funhouse/peripherals.py | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43d1385..1b9fadc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: name: pylint (library code) types: [python] args: - - --disable=consider-using-f-string,duplicate-code + - --disable=consider-using-f-string exclude: "^(docs/|examples/|tests/|setup.py$)" - id: pylint name: pylint (example code) diff --git a/adafruit_funhouse/__init__.py b/adafruit_funhouse/__init__.py index 8830bf1..3ea2813 100755 --- a/adafruit_funhouse/__init__.py +++ b/adafruit_funhouse/__init__.py @@ -72,7 +72,7 @@ def __init__( self, *, url: Optional[str] = None, - headers: Dict[str, str] = None, + headers: Optional[Dict[str, str]] = None, json_path: Optional[Union[List[str], List[List[str]]]] = None, regexp_path: Optional[Sequence[str]] = None, default_bg: int = 0, diff --git a/adafruit_funhouse/peripherals.py b/adafruit_funhouse/peripherals.py index 5ff36ae..42a0352 100755 --- a/adafruit_funhouse/peripherals.py +++ b/adafruit_funhouse/peripherals.py @@ -27,7 +27,6 @@ """ -from typing import Optional import board from digitalio import DigitalInOut, Direction, Pull from analogio import AnalogIn @@ -37,6 +36,11 @@ import adafruit_ahtx0 import adafruit_dotstar +try: + from typing import Optional +except ImportError: + pass + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse.git" @@ -91,7 +95,7 @@ def __init__(self) -> None: self._pir.direction = Direction.INPUT @staticmethod - def play_tone(frequency: float, duration: float) -> None: + def play_tone(frequency: int, duration: float) -> None: """Automatically Enable/Disable the speaker and play a tone at the specified frequency for the specified duration It will attempt to play the sound up to 3 times in the case of From 5bb0fb166448b3510836f500466e7626e029d14a Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 15 Nov 2021 12:12:49 -0500 Subject: [PATCH 9/9] Revert "Changes per review" This reverts commit 2980950d7683e3a5a3a2e925871df9fa245a1448. --- .pre-commit-config.yaml | 2 +- adafruit_funhouse/__init__.py | 2 +- adafruit_funhouse/peripherals.py | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1b9fadc..43d1385 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: name: pylint (library code) types: [python] args: - - --disable=consider-using-f-string + - --disable=consider-using-f-string,duplicate-code exclude: "^(docs/|examples/|tests/|setup.py$)" - id: pylint name: pylint (example code) diff --git a/adafruit_funhouse/__init__.py b/adafruit_funhouse/__init__.py index 3ea2813..8830bf1 100755 --- a/adafruit_funhouse/__init__.py +++ b/adafruit_funhouse/__init__.py @@ -72,7 +72,7 @@ def __init__( self, *, url: Optional[str] = None, - headers: Optional[Dict[str, str]] = None, + headers: Dict[str, str] = None, json_path: Optional[Union[List[str], List[List[str]]]] = None, regexp_path: Optional[Sequence[str]] = None, default_bg: int = 0, diff --git a/adafruit_funhouse/peripherals.py b/adafruit_funhouse/peripherals.py index 42a0352..5ff36ae 100755 --- a/adafruit_funhouse/peripherals.py +++ b/adafruit_funhouse/peripherals.py @@ -27,6 +27,7 @@ """ +from typing import Optional import board from digitalio import DigitalInOut, Direction, Pull from analogio import AnalogIn @@ -36,11 +37,6 @@ import adafruit_ahtx0 import adafruit_dotstar -try: - from typing import Optional -except ImportError: - pass - __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse.git" @@ -95,7 +91,7 @@ def __init__(self) -> None: self._pir.direction = Direction.INPUT @staticmethod - def play_tone(frequency: int, duration: float) -> None: + def play_tone(frequency: float, duration: float) -> None: """Automatically Enable/Disable the speaker and play a tone at the specified frequency for the specified duration It will attempt to play the sound up to 3 times in the case of