Skip to content

Commit b7f18b1

Browse files
committed
correct Missing Type Annotations #17
1 parent cfe93c6 commit b7f18b1

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

adafruit_hue.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
from simpleio import map_range
3131

3232
try:
33-
from typing import Optional, List, Union, Any
33+
from typing import Optional, List, Union, Sequence, Any
34+
from circuitpython_typing.http import HTTPProtocol
3435
except ImportError:
3536
pass
3637

@@ -45,7 +46,7 @@ class Bridge:
4546

4647
def __init__(
4748
self,
48-
wifi_manager: Any,
49+
wifi_manager: HTTPProtocol,
4950
bridge_ip: Optional[str] = None,
5051
username: Optional[str] = None,
5152
) -> None:
@@ -65,7 +66,7 @@ def __init__(
6566
self._username_url = self._bridge_url + "/" + self._username
6667

6768
@staticmethod
68-
def rgb_to_hsb(rgb: tuple) -> tuple:
69+
def rgb_to_hsb(rgb: Sequence[int]) -> Sequence[int]:
6970
"""Returns RGB values as a HSL tuple.
7071
:param list rgb: RGB Values
7172
"""
@@ -142,14 +143,15 @@ def register_username(self) -> str:
142143
# Lights API
143144
def show_light_info(self, light_id: Union[int, str]) -> str:
144145
"""Gets the attributes and state of a given light.
145-
:param int light_id: Light identifier.
146+
:param int|str light_id: Light identifier.
146147
"""
147148
resp = self._get(f"{self._username_url}/lights/{light_id}")
148149
return resp
149150

150151
def set_light(self, light_id: Union[int, str], **kwargs) -> str:
151152
"""Allows the user to turn the light on and off, modify the hue and effects.
152153
You can pass the following as valid kwargs into this method:
154+
:param int|str light_id: Light identifier
153155
:param bool on: On/Off state of the light
154156
:param int bri: Brightness value of the light, 0-100% (1 to 254)
155157
:param int hue: Hue value to set the light, in degrees (0 to 360) (0 to 65535)
@@ -162,7 +164,7 @@ def set_light(self, light_id: Union[int, str], **kwargs) -> str:
162164

163165
def toggle_light(self, light_id: Union[int, str]) -> str:
164166
"""Gets and toggles the current state of a specified light.
165-
:param int light_id: Light identifier.
167+
:param int|str light_id: Light identifier.
166168
"""
167169
light_state = self.get_light(light_id)
168170
light_state = not light_state["state"]["on"]
@@ -171,20 +173,18 @@ def toggle_light(self, light_id: Union[int, str]) -> str:
171173

172174
def get_light(self, light_id: Union[int, str]) -> str:
173175
"""Gets the attributes and state of a provided light.
174-
:param int light_id: Light identifier.
176+
:param int|str light_id: Light identifier.
175177
"""
176178
resp = self._get(f"{self._username_url}/lights/{light_id}")
177179
return resp
178180

179-
def get_lights(self) -> str:
181+
def get_lights(self) -> Any:
180182
"""Returns all the light resources available for a bridge."""
181183
resp = self._get(self._username_url + "/lights")
182184
return resp
183185

184186
# Groups API
185-
def create_group(
186-
self, lights: List[Union[int, str]], group_id: Optional[str]
187-
) -> str:
187+
def create_group(self, lights: List[Union[int, str]], group_id: str) -> Any:
188188
"""Creates a new group containing the lights specified and optional name.
189189
:param list lights: List of light identifiers.
190190
:param str group_id: Optional group name.
@@ -193,9 +193,9 @@ def create_group(
193193
resp = self._post(self._username_url + "/groups", data)
194194
return resp
195195

196-
def set_group(self, group_id: Union[int, str], **kwargs) -> str:
196+
def set_group(self, group_id: Union[int, str], **kwargs) -> Any:
197197
"""Allows the user to turn the light on and off, modify the hue and effects.
198-
:param int group_id: Group identifier.
198+
:param int|str group_id: Group identifier.
199199
You can pass the following as (optional) valid kwargs into this method:
200200
:param bool on: On/Off state of the light
201201
:param int bri: Brightness value of the light (1 to 254)
@@ -207,26 +207,27 @@ def set_group(self, group_id: Union[int, str], **kwargs) -> str:
207207
resp = self._put(f"{self._username_url}/groups/{group_id}/action", kwargs)
208208
return resp
209209

210-
def get_groups(self) -> str:
210+
def get_groups(self) -> Any:
211211
"""Returns all the light groups available for a bridge."""
212212
resp = self._get(self._username_url + "/groups")
213213
return resp
214214

215215
# Scene API
216-
def set_scene(self, group_id: Union[int, str], scene_id: str):
216+
def set_scene(self, group_id: Union[int, str], scene_id: str) -> None:
217217
"""Sets a group scene.
218+
:param int|str group_id: the group identifier
218219
:param str scene: The scene identifier
219220
"""
220221
# To recall an existing scene, use the Groups API.
221222
self.set_group(group_id, scene=scene_id)
222223

223-
def get_scenes(self) -> str:
224+
def get_scenes(self) -> Any:
224225
"""Returns a list of all scenes currently stored in the bridge."""
225226
resp = self._get(self._username_url + "/scenes")
226227
return resp
227228

228229
# HTTP Helpers for the Hue API
229-
def _post(self, path: str, data: str) -> str:
230+
def _post(self, path: str, data: str) -> Any:
230231
"""POST data
231232
:param str path: Formatted Hue API URL
232233
:param json data: JSON data to POST to the Hue API.
@@ -236,7 +237,7 @@ def _post(self, path: str, data: str) -> str:
236237
resp.close()
237238
return resp_json
238239

239-
def _put(self, path: str, data: str):
240+
def _put(self, path: str, data: str) -> Any:
240241
"""PUT data
241242
:param str path: Formatted Hue API URL
242243
:param json data: JSON data to PUT to the Hue API.
@@ -246,7 +247,7 @@ def _put(self, path: str, data: str):
246247
resp.close()
247248
return resp_json
248249

249-
def _get(self, path: str, data: Optional[str] = None):
250+
def _get(self, path: str, data: Optional[str] = None) -> Any:
250251
"""GET data
251252
:param str path: Formatted Hue API URL
252253
:param json data: JSON data to GET from the Hue API.

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
Adafruit-Blinka
66
adafruit-circuitpython-simpleio
77
adafruit-circuitpython-esp32spi
8+
adafruit-circuitpython-typing

0 commit comments

Comments
 (0)