Skip to content

Commit 87a3722

Browse files
committed
Add type hints
1 parent 4c01fa1 commit 87a3722

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

adafruit_funhouse/graphics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Graphics(GraphicsBase):
4545
"""
4646

4747
# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements, too-few-public-methods
48-
def __init__(self, *, default_bg=0, rotation=270, scale=1, debug=False):
48+
def __init__(self, *, default_bg: int = 0, rotation: int = 270, scale: int = 1, debug: bool = False):
4949
self._debug = debug
5050
self.display = board.DISPLAY
5151
self.display.rotation = rotation

adafruit_funhouse/network.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
from adafruit_portalbase.network import NetworkBase
3434
from adafruit_portalbase.wifi_esp32s2 import WiFi
3535

36+
try:
37+
from typing import Optional, Union
38+
from adafruit_dotstar import DotStar
39+
except ImportError:
40+
pass
41+
3642
__version__ = "0.0.0-auto.0"
3743
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse.git"
3844

@@ -54,9 +60,9 @@ class Network(NetworkBase):
5460
def __init__(
5561
self,
5662
*,
57-
status_dotstar=None,
58-
extract_values=True,
59-
debug=False,
63+
status_dotstar: Optional[DotStar] = None,
64+
extract_values: bool = True,
65+
debug: bool = False,
6066
):
6167
super().__init__(
6268
WiFi(status_led=status_dotstar),
@@ -65,7 +71,7 @@ def __init__(
6571
)
6672
self._mqtt_client = None
6773

68-
def init_io_mqtt(self):
74+
def init_io_mqtt(self) -> IO_MQTT:
6975
"""Initialize MQTT for Adafruit IO"""
7076
try:
7177
aio_username = self._secrets["aio_username"]
@@ -80,12 +86,12 @@ def init_io_mqtt(self):
8086
# pylint: disable=too-many-arguments
8187
def init_mqtt(
8288
self,
83-
broker,
84-
port=8883,
85-
username=None,
86-
password=None,
87-
use_io=False,
88-
):
89+
broker: str,
90+
port: int = 8883,
91+
username: str = None,
92+
password: str = None,
93+
use_io: bool = False,
94+
) -> Union[MQTT, IO_MQTT]:
8995
"""Initialize MQTT"""
9096
self.connect()
9197
self._mqtt_client = MQTT.MQTT(
@@ -103,12 +109,12 @@ def init_mqtt(
103109

104110
# pylint: enable=too-many-arguments
105111

106-
def _get_mqtt_client(self):
112+
def _get_mqtt_client(self) -> Union[MQTT, IO_MQTT]:
107113
if self._mqtt_client is not None:
108114
return self._mqtt_client
109115
raise RuntimeError("Please initialize MQTT before using")
110116

111-
def mqtt_loop(self, *args, suppress_mqtt_errors=True, **kwargs):
117+
def mqtt_loop(self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int):
112118
"""Run the MQTT Loop"""
113119
self._get_mqtt_client()
114120
if suppress_mqtt_errors:
@@ -123,7 +129,7 @@ def mqtt_loop(self, *args, suppress_mqtt_errors=True, **kwargs):
123129
if self._mqtt_client is not None:
124130
self._mqtt_client.loop(*args, **kwargs)
125131

126-
def mqtt_publish(self, *args, suppress_mqtt_errors=True, **kwargs):
132+
def mqtt_publish(self, *args: Union[str, int, float], suppress_mqtt_errors: bool = True, **kwargs: Union[str, int, float]):
127133
"""Publish to MQTT"""
128134
self._get_mqtt_client()
129135
if suppress_mqtt_errors:
@@ -136,7 +142,7 @@ def mqtt_publish(self, *args, suppress_mqtt_errors=True, **kwargs):
136142
if self._mqtt_client is not None:
137143
self._mqtt_client.publish(*args, **kwargs)
138144

139-
def mqtt_connect(self, *args, **kwargs):
145+
def mqtt_connect(self, *args: Union[bool, str, int], **kwargs: Union[bool, str, int]):
140146
"""Connect to MQTT"""
141147
self._get_mqtt_client()
142148
if self._mqtt_client is not None:
@@ -153,7 +159,7 @@ def on_mqtt_connect(self):
153159
return None
154160

155161
@on_mqtt_connect.setter
156-
def on_mqtt_connect(self, value):
162+
def on_mqtt_connect(self, value: function):
157163
self._get_mqtt_client()
158164
self._mqtt_client.on_connect = value
159165

@@ -168,7 +174,7 @@ def on_mqtt_disconnect(self):
168174
return None
169175

170176
@on_mqtt_disconnect.setter
171-
def on_mqtt_disconnect(self, value):
177+
def on_mqtt_disconnect(self, value: function):
172178
self._get_mqtt_client().on_disconnect = value
173179

174180
@property
@@ -182,7 +188,7 @@ def on_mqtt_subscribe(self):
182188
return None
183189

184190
@on_mqtt_subscribe.setter
185-
def on_mqtt_subscribe(self, value):
191+
def on_mqtt_subscribe(self, value: function):
186192
self._get_mqtt_client().on_subscribe = value
187193

188194
@property
@@ -196,7 +202,7 @@ def on_mqtt_unsubscribe(self):
196202
return None
197203

198204
@on_mqtt_unsubscribe.setter
199-
def on_mqtt_unsubscribe(self, value):
205+
def on_mqtt_unsubscribe(self, value: function):
200206
self._get_mqtt_client().on_unsubscribe = value
201207

202208
@property
@@ -210,7 +216,7 @@ def on_mqtt_message(self):
210216
return None
211217

212218
@on_mqtt_message.setter
213-
def on_mqtt_message(self, value):
219+
def on_mqtt_message(self, value: function):
214220
self._get_mqtt_client().on_message = value
215221

216222
@property
@@ -222,5 +228,5 @@ def enabled(self):
222228
return self._wifi.enabled
223229

224230
@enabled.setter
225-
def enabled(self, value):
231+
def enabled(self, value: bool):
226232
self._wifi.enabled = bool(value)

adafruit_funhouse/peripherals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def play_tone(frequency, duration):
108108
pass
109109
attempt += 1
110110

111-
def set_dotstars(self, *values):
111+
def set_dotstars(self, *values: int):
112112
"""Set the dotstar values to the provided values"""
113113
for i, value in enumerate(values[: len(self.dotstars)]):
114114
self.dotstars[i] = value
@@ -234,7 +234,7 @@ def led(self):
234234
return self._led.value
235235

236236
@led.setter
237-
def led(self, value):
237+
def led(self, value: bool):
238238
self._led.value = bool(value)
239239

240240
@property

0 commit comments

Comments
 (0)