Skip to content

Commit 5969636

Browse files
committed
Added missing typehints
1 parent 5515c91 commit 5969636

File tree

4 files changed

+55
-48
lines changed

4 files changed

+55
-48
lines changed

adafruit_funhouse/__init__.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
from adafruit_funhouse.graphics import Graphics
3535
from adafruit_funhouse.peripherals import Peripherals
3636

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

@@ -65,17 +71,17 @@ class FunHouse(PortalBase):
6571
def __init__(
6672
self,
6773
*,
68-
url=None,
69-
headers=None,
70-
json_path=None,
71-
regexp_path=None,
72-
default_bg=0,
73-
status_dotstar=None,
74-
json_transform=None,
75-
rotation=270,
76-
scale=1,
77-
debug=False,
78-
):
74+
url: Optional[str] = None,
75+
headers: Dict[str, str] = None,
76+
json_path: Optional[Union[List[str], List[List[str]]]] = None,
77+
regexp_path: Optional[Sequence[str]] = None,
78+
default_bg: int = 0,
79+
status_dotstar: Optional[DotStar] = None,
80+
json_transform: Optional[Union[Callable, List[Callable]]] = None,
81+
rotation: int = 270,
82+
scale: int = 1,
83+
debug: bool = False,
84+
) -> None:
7985

8086
network = Network(
8187
status_dotstar=status_dotstar,
@@ -105,7 +111,7 @@ def __init__(
105111

106112
gc.collect()
107113

108-
def enter_light_sleep(self, sleep_time):
114+
def enter_light_sleep(self, sleep_time: float) -> None:
109115
"""
110116
Enter light sleep and resume the program after a certain period of time.
111117

adafruit_funhouse/graphics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252
rotation: int = 270,
5353
scale: int = 1,
5454
debug: bool = False
55-
):
55+
) -> None:
5656
self._debug = debug
5757
self.display = board.DISPLAY
5858
self.display.rotation = rotation

adafruit_funhouse/network.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(
6363
status_dotstar: Optional[DotStar] = None,
6464
extract_values: bool = True,
6565
debug: bool = False,
66-
):
66+
) -> None:
6767
super().__init__(
6868
WiFi(status_led=status_dotstar),
6969
extract_values=extract_values,
@@ -114,7 +114,7 @@ def _get_mqtt_client(self) -> Union[MQTT.MQTT, IO_MQTT]:
114114
return self._mqtt_client
115115
raise RuntimeError("Please initialize MQTT before using")
116116

117-
def mqtt_loop(self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int):
117+
def mqtt_loop(self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int) -> None:
118118
"""Run the MQTT Loop"""
119119
self._get_mqtt_client()
120120
if suppress_mqtt_errors:
@@ -134,7 +134,7 @@ def mqtt_publish(
134134
*args: Union[str, int, float],
135135
suppress_mqtt_errors: bool = True,
136136
**kwargs: Union[str, int, float]
137-
):
137+
) -> None:
138138
"""Publish to MQTT"""
139139
self._get_mqtt_client()
140140
if suppress_mqtt_errors:
@@ -149,14 +149,14 @@ def mqtt_publish(
149149

150150
def mqtt_connect(
151151
self, *args: Union[bool, str, int], **kwargs: Union[bool, str, int]
152-
):
152+
) -> None:
153153
"""Connect to MQTT"""
154154
self._get_mqtt_client()
155155
if self._mqtt_client is not None:
156156
self._mqtt_client.connect(*args, **kwargs)
157157

158158
@property
159-
def on_mqtt_connect(self):
159+
def on_mqtt_connect(self) -> Optional[Callable]:
160160
"""
161161
Get or Set the MQTT Connect Handler
162162
@@ -166,12 +166,12 @@ def on_mqtt_connect(self):
166166
return None
167167

168168
@on_mqtt_connect.setter
169-
def on_mqtt_connect(self, value: Callable):
169+
def on_mqtt_connect(self, value: Callable) -> None:
170170
self._get_mqtt_client()
171171
self._mqtt_client.on_connect = value
172172

173173
@property
174-
def on_mqtt_disconnect(self):
174+
def on_mqtt_disconnect(self) -> Optional[Callable]:
175175
"""
176176
Get or Set the MQTT Disconnect Handler
177177
@@ -181,11 +181,11 @@ def on_mqtt_disconnect(self):
181181
return None
182182

183183
@on_mqtt_disconnect.setter
184-
def on_mqtt_disconnect(self, value: Callable):
184+
def on_mqtt_disconnect(self, value: Callable) -> None:
185185
self._get_mqtt_client().on_disconnect = value
186186

187187
@property
188-
def on_mqtt_subscribe(self):
188+
def on_mqtt_subscribe(self) -> Optional[Callable]:
189189
"""
190190
Get or Set the MQTT Subscribe Handler
191191
@@ -195,11 +195,11 @@ def on_mqtt_subscribe(self):
195195
return None
196196

197197
@on_mqtt_subscribe.setter
198-
def on_mqtt_subscribe(self, value: Callable):
198+
def on_mqtt_subscribe(self, value: Callable) -> None:
199199
self._get_mqtt_client().on_subscribe = value
200200

201201
@property
202-
def on_mqtt_unsubscribe(self):
202+
def on_mqtt_unsubscribe(self) -> Optional[Callable]:
203203
"""
204204
Get or Set the MQTT Unsubscribe Handler
205205
@@ -209,11 +209,11 @@ def on_mqtt_unsubscribe(self):
209209
return None
210210

211211
@on_mqtt_unsubscribe.setter
212-
def on_mqtt_unsubscribe(self, value: Callable):
212+
def on_mqtt_unsubscribe(self, value: Callable) -> None:
213213
self._get_mqtt_client().on_unsubscribe = value
214214

215215
@property
216-
def on_mqtt_message(self):
216+
def on_mqtt_message(self) -> Optional[Callable]:
217217
"""
218218
Get or Set the MQTT Message Handler
219219
@@ -223,17 +223,17 @@ def on_mqtt_message(self):
223223
return None
224224

225225
@on_mqtt_message.setter
226-
def on_mqtt_message(self, value: Callable):
226+
def on_mqtt_message(self, value: Callable) -> None:
227227
self._get_mqtt_client().on_message = value
228228

229229
@property
230-
def enabled(self):
230+
def enabled(self) -> bool:
231231
"""
232232
Get or Set whether the WiFi is enabled
233233
234234
"""
235235
return self._wifi.enabled
236236

237237
@enabled.setter
238-
def enabled(self, value: bool):
238+
def enabled(self, value: bool) -> None:
239239
self._wifi.enabled = bool(value)

adafruit_funhouse/peripherals.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
2828
"""
2929

30+
from typing import Optional
3031
import board
3132
from digitalio import DigitalInOut, Direction, Pull
3233
from analogio import AnalogIn
@@ -44,7 +45,7 @@ class Peripherals:
4445
"""Peripherals Helper Class for the FunHouse Library"""
4546

4647
# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements
47-
def __init__(self):
48+
def __init__(self) -> None:
4849
# Dotstars
4950
self.dotstars = adafruit_dotstar.DotStar(
5051
board.DOTSTAR_CLOCK, board.DOTSTAR_DATA, 5, brightness=0.3
@@ -90,7 +91,7 @@ def __init__(self):
9091
self._pir.direction = Direction.INPUT
9192

9293
@staticmethod
93-
def play_tone(frequency, duration):
94+
def play_tone(frequency: float, duration: float) -> None:
9495
"""Automatically Enable/Disable the speaker and play
9596
a tone at the specified frequency for the specified duration
9697
It will attempt to play the sound up to 3 times in the case of
@@ -108,12 +109,12 @@ def play_tone(frequency, duration):
108109
pass
109110
attempt += 1
110111

111-
def set_dotstars(self, *values: int):
112+
def set_dotstars(self, *values: int) -> None:
112113
"""Set the dotstar values to the provided values"""
113114
for i, value in enumerate(values[: len(self.dotstars)]):
114115
self.dotstars[i] = value
115116

116-
def deinit(self):
117+
def deinit(self) -> None:
117118
"""Call deinit on all resources to free them"""
118119
self.dotstars.deinit()
119120
for button in self._buttons:
@@ -125,56 +126,56 @@ def deinit(self):
125126
self._pir.deinit()
126127

127128
@property
128-
def button_down(self):
129+
def button_down(self) -> bool:
129130
"""
130131
Return whether Down Button is pressed
131132
"""
132133
return self._buttons[0].value
133134

134135
@property
135-
def button_sel(self):
136+
def button_sel(self) -> bool:
136137
"""
137138
Return whether Sel Button is pressed
138139
"""
139140
return self._buttons[1].value
140141

141142
@property
142-
def button_up(self):
143+
def button_up(self) -> bool:
143144
"""
144145
Return whether Up Button is pressed
145146
"""
146147
return self._buttons[2].value
147148

148149
@property
149-
def any_button_pressed(self):
150+
def any_button_pressed(self) -> bool:
150151
"""
151152
Return whether any button is pressed
152153
"""
153154
return True in [button.value for button in enumerate(self._buttons)]
154155

155156
@property
156-
def captouch6(self):
157+
def captouch6(self) -> bool:
157158
"""
158159
Return whether CT6 Touch Pad is touched
159160
"""
160161
return self._ctp[0].value
161162

162163
@property
163-
def captouch7(self):
164+
def captouch7(self) -> bool:
164165
"""
165166
Return whether CT7 Touch Pad is touched
166167
"""
167168
return self._ctp[1].value
168169

169170
@property
170-
def captouch8(self):
171+
def captouch8(self) -> bool:
171172
"""
172173
Return whether CT8 Touch Pad is touched
173174
"""
174175
return self._ctp[2].value
175176

176177
@property
177-
def slider(self):
178+
def slider(self) -> Optional[float]:
178179
"""
179180
Return the slider position value in the range of 0.0-1.0 or None if not touched
180181
"""
@@ -186,7 +187,7 @@ def slider(self):
186187
return cap_map.index(val) / 8 if val in cap_map else None
187188

188189
@property
189-
def light(self):
190+
def light(self) -> int:
190191
"""
191192
Return the value of the light sensor. The neopixel_disable property
192193
must be false to get a value.
@@ -206,39 +207,39 @@ def light(self):
206207
return self._light.value
207208

208209
@property
209-
def temperature(self):
210+
def temperature(self) -> float:
210211
"""
211212
Return the temperature in degrees Celsius
212213
"""
213214
return self._aht20.temperature
214215

215216
@property
216-
def relative_humidity(self):
217+
def relative_humidity(self) -> float:
217218
"""
218219
Return the relative humidity as a percentage (0 - 100)
219220
"""
220221
return self._aht20.relative_humidity
221222

222223
@property
223-
def pressure(self):
224+
def pressure(self) -> float:
224225
"""
225226
Return the barometric pressure in hPa, or equivalently in mBar
226227
"""
227228
return self._dps310.pressure
228229

229230
@property
230-
def led(self):
231+
def led(self) -> bool:
231232
"""
232233
Return or set the value of the LED
233234
"""
234235
return self._led.value
235236

236237
@led.setter
237-
def led(self, value: bool):
238+
def led(self, value: bool) -> None:
238239
self._led.value = bool(value)
239240

240241
@property
241-
def pir_sensor(self):
242+
def pir_sensor(self) -> bool:
242243
"""
243244
Return the value of the PIR Sensor
244245
"""

0 commit comments

Comments
 (0)