30
30
from simpleio import map_range
31
31
32
32
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
34
35
except ImportError :
35
36
pass
36
37
@@ -45,7 +46,7 @@ class Bridge:
45
46
46
47
def __init__ (
47
48
self ,
48
- wifi_manager : Any ,
49
+ wifi_manager : HTTPProtocol ,
49
50
bridge_ip : Optional [str ] = None ,
50
51
username : Optional [str ] = None ,
51
52
) -> None :
@@ -65,7 +66,7 @@ def __init__(
65
66
self ._username_url = self ._bridge_url + "/" + self ._username
66
67
67
68
@staticmethod
68
- def rgb_to_hsb (rgb : tuple ) -> tuple :
69
+ def rgb_to_hsb (rgb : Sequence [ int ] ) -> Sequence [ int ] :
69
70
"""Returns RGB values as a HSL tuple.
70
71
:param list rgb: RGB Values
71
72
"""
@@ -142,14 +143,15 @@ def register_username(self) -> str:
142
143
# Lights API
143
144
def show_light_info (self , light_id : Union [int , str ]) -> str :
144
145
"""Gets the attributes and state of a given light.
145
- :param int light_id: Light identifier.
146
+ :param int|str light_id: Light identifier.
146
147
"""
147
148
resp = self ._get (f"{ self ._username_url } /lights/{ light_id } " )
148
149
return resp
149
150
150
151
def set_light (self , light_id : Union [int , str ], ** kwargs ) -> str :
151
152
"""Allows the user to turn the light on and off, modify the hue and effects.
152
153
You can pass the following as valid kwargs into this method:
154
+ :param int|str light_id: Light identifier
153
155
:param bool on: On/Off state of the light
154
156
:param int bri: Brightness value of the light, 0-100% (1 to 254)
155
157
: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:
162
164
163
165
def toggle_light (self , light_id : Union [int , str ]) -> str :
164
166
"""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.
166
168
"""
167
169
light_state = self .get_light (light_id )
168
170
light_state = not light_state ["state" ]["on" ]
@@ -171,20 +173,18 @@ def toggle_light(self, light_id: Union[int, str]) -> str:
171
173
172
174
def get_light (self , light_id : Union [int , str ]) -> str :
173
175
"""Gets the attributes and state of a provided light.
174
- :param int light_id: Light identifier.
176
+ :param int|str light_id: Light identifier.
175
177
"""
176
178
resp = self ._get (f"{ self ._username_url } /lights/{ light_id } " )
177
179
return resp
178
180
179
- def get_lights (self ) -> str :
181
+ def get_lights (self ) -> Any :
180
182
"""Returns all the light resources available for a bridge."""
181
183
resp = self ._get (self ._username_url + "/lights" )
182
184
return resp
183
185
184
186
# 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 :
188
188
"""Creates a new group containing the lights specified and optional name.
189
189
:param list lights: List of light identifiers.
190
190
:param str group_id: Optional group name.
@@ -193,9 +193,9 @@ def create_group(
193
193
resp = self ._post (self ._username_url + "/groups" , data )
194
194
return resp
195
195
196
- def set_group (self , group_id : Union [int , str ], ** kwargs ) -> str :
196
+ def set_group (self , group_id : Union [int , str ], ** kwargs ) -> Any :
197
197
"""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.
199
199
You can pass the following as (optional) valid kwargs into this method:
200
200
:param bool on: On/Off state of the light
201
201
: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:
207
207
resp = self ._put (f"{ self ._username_url } /groups/{ group_id } /action" , kwargs )
208
208
return resp
209
209
210
- def get_groups (self ) -> str :
210
+ def get_groups (self ) -> Any :
211
211
"""Returns all the light groups available for a bridge."""
212
212
resp = self ._get (self ._username_url + "/groups" )
213
213
return resp
214
214
215
215
# 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 :
217
217
"""Sets a group scene.
218
+ :param int|str group_id: the group identifier
218
219
:param str scene: The scene identifier
219
220
"""
220
221
# To recall an existing scene, use the Groups API.
221
222
self .set_group (group_id , scene = scene_id )
222
223
223
- def get_scenes (self ) -> str :
224
+ def get_scenes (self ) -> Any :
224
225
"""Returns a list of all scenes currently stored in the bridge."""
225
226
resp = self ._get (self ._username_url + "/scenes" )
226
227
return resp
227
228
228
229
# HTTP Helpers for the Hue API
229
- def _post (self , path : str , data : str ) -> str :
230
+ def _post (self , path : str , data : str ) -> Any :
230
231
"""POST data
231
232
:param str path: Formatted Hue API URL
232
233
:param json data: JSON data to POST to the Hue API.
@@ -236,7 +237,7 @@ def _post(self, path: str, data: str) -> str:
236
237
resp .close ()
237
238
return resp_json
238
239
239
- def _put (self , path : str , data : str ):
240
+ def _put (self , path : str , data : str ) -> Any :
240
241
"""PUT data
241
242
:param str path: Formatted Hue API URL
242
243
:param json data: JSON data to PUT to the Hue API.
@@ -246,7 +247,7 @@ def _put(self, path: str, data: str):
246
247
resp .close ()
247
248
return resp_json
248
249
249
- def _get (self , path : str , data : Optional [str ] = None ):
250
+ def _get (self , path : str , data : Optional [str ] = None ) -> Any :
250
251
"""GET data
251
252
:param str path: Formatted Hue API URL
252
253
:param json data: JSON data to GET from the Hue API.
0 commit comments