@@ -137,7 +137,7 @@ async def request(
137137 the WLED device.
138138
139139 Args:
140- uri: Request URI, for example `si`.
140+ uri: Request URI, for example `/json/ si`.
141141 method: HTTP method to use for the request.E.g., "GET" or "POST".
142142 data: Dictionary of data to send to the WLED device.
143143
@@ -152,9 +152,7 @@ async def request(
152152 with the WLED device.
153153 WLEDError: Received an unexpected response from the WLED device.
154154 """
155- url = URL .build (scheme = "http" , host = self .host , port = 80 , path = "/json/" ).join (
156- URL (uri )
157- )
155+ url = URL .build (scheme = "http" , host = self .host , port = 80 , path = uri )
158156
159157 headers = {
160158 "Accept" : "application/json, text/plain, */*" ,
@@ -165,7 +163,7 @@ async def request(
165163 self ._close_session = True
166164
167165 # If updating the state, always request for a state response
168- if method == "POST" and uri == "state" and data is not None :
166+ if method == "POST" and uri == "/json/ state" and data is not None :
169167 data ["v" ] = True
170168
171169 try :
@@ -198,7 +196,7 @@ async def request(
198196 response_data = await response .json ()
199197 if (
200198 method == "POST"
201- and uri == "state"
199+ and uri == "/json/ state"
202200 and self ._device is not None
203201 and data is not None
204202 ):
@@ -226,7 +224,7 @@ async def update(self, full_update: bool = False) -> Device:
226224 WLEDEmptyResponseError: The WLED device returned an empty response.
227225 """
228226 if self ._device is None or full_update :
229- data = await self .request ()
227+ data = await self .request ("/json" )
230228 if not data :
231229 raise WLEDEmptyResponseError (
232230 f"WLED device at { self .host } returned an empty API"
@@ -244,7 +242,7 @@ async def update(self, full_update: bool = False) -> Device:
244242 except version .InvalidVersion :
245243 # Could be a manual build one? Lets poll for it
246244 try :
247- await self .request ("si" )
245+ await self .request ("/json/ si" )
248246 self ._supports_si_request = True
249247 except WLEDError :
250248 self ._supports_si_request = False
@@ -253,14 +251,14 @@ async def update(self, full_update: bool = False) -> Device:
253251
254252 # Handle legacy state and update in separate requests
255253 if not self ._supports_si_request :
256- info = await self .request ("info" )
254+ info = await self .request ("/json/ info" )
257255 if not info :
258256 raise WLEDEmptyResponseError (
259257 f"WLED device at { self .host } returned an empty API"
260258 " response on info update"
261259 )
262260
263- state = await self .request ("state" )
261+ state = await self .request ("/json/ state" )
264262 if not state :
265263 raise WLEDEmptyResponseError (
266264 f"WLED device { self .host } returned an empty API"
@@ -269,7 +267,7 @@ async def update(self, full_update: bool = False) -> Device:
269267 self ._device .update_from_dict ({"info" : info , "state" : state })
270268 return self ._device
271269
272- state_info = await self .request ("si" )
270+ state_info = await self .request ("/json/ si" )
273271 if not state_info :
274272 raise WLEDEmptyResponseError (
275273 f"WLED device at { self .host } returned an empty API"
@@ -305,7 +303,7 @@ async def master(
305303 if transition is not None :
306304 state ["tt" ] = transition
307305
308- await self .request ("state" , method = "POST" , data = state )
306+ await self .request ("/json/ state" , method = "POST" , data = state )
309307
310308 async def segment ( # pylint: disable=too-many-locals, too-many-branches
311309 self ,
@@ -442,7 +440,7 @@ async def segment( # pylint: disable=too-many-locals, too-many-branches
442440 if transition is not None :
443441 state ["tt" ] = transition
444442
445- await self .request ("state" , method = "POST" , data = state )
443+ await self .request ("/json/ state" , method = "POST" , data = state )
446444
447445 async def transition (self , transition : int ) -> None :
448446 """Set the default transition time for manual control.
@@ -452,23 +450,25 @@ async def transition(self, transition: int) -> None:
452450 colors/brightness levels. One unit is 100ms, so a value of 4
453451 results in a transition of 400ms.
454452 """
455- await self .request ("state" , method = "POST" , data = {"transition" : transition })
453+ await self .request (
454+ "/json/state" , method = "POST" , data = {"transition" : transition }
455+ )
456456
457457 async def preset (self , preset : int ) -> None :
458458 """Set a preset on a WLED device.
459459
460460 Args:
461461 preset: The preset number to activate on this WLED device.
462462 """
463- await self .request ("state" , method = "POST" , data = {"ps" : preset })
463+ await self .request ("/json/ state" , method = "POST" , data = {"ps" : preset })
464464
465465 async def live (self , live : Live ) -> None :
466466 """Set the live override mode on a WLED device.
467467
468468 Args:
469469 live: The live override mode to set on this WLED device.
470470 """
471- await self .request ("state" , method = "POST" , data = {"lor" : live .value })
471+ await self .request ("/json/ state" , method = "POST" , data = {"lor" : live .value })
472472
473473 async def playlist (self , playlist : int ) -> None :
474474 """Set a running playlist on a WLED device.
@@ -477,7 +477,7 @@ async def playlist(self, playlist: int) -> None:
477477 playlist: ID of playlist to run. For now, this sets the preset
478478 cycle feature, -1 is off and 0 is on.
479479 """
480- await self .request ("state" , method = "POST" , data = {"pl" : playlist })
480+ await self .request ("/json/ state" , method = "POST" , data = {"pl" : playlist })
481481
482482 async def sync (
483483 self , * , send : bool | None = None , receive : bool | None = None
@@ -490,7 +490,7 @@ async def sync(
490490 """
491491 sync = {"send" : send , "recv" : receive }
492492 sync = {k : v for k , v in sync .items () if v is not None }
493- await self .request ("state" , method = "POST" , data = {"udpn" : sync })
493+ await self .request ("/json/ state" , method = "POST" , data = {"udpn" : sync })
494494
495495 async def nightlight (
496496 self ,
@@ -524,7 +524,11 @@ async def nightlight(
524524 if on :
525525 state ["on" ] = True
526526
527- await self .request ("state" , method = "POST" , data = state )
527+ await self .request ("/json/state" , method = "POST" , data = state )
528+
529+ async def reset (self ) -> None :
530+ """Reboot WLED device."""
531+ await self .request ("/reset" )
528532
529533 async def close (self ) -> None :
530534 """Close open client (WebSocket) session."""
@@ -546,5 +550,4 @@ async def __aexit__(self, *_exc_info) -> None:
546550 Args:
547551 _exc_info: Exec type.
548552 """
549- print ("Disconnecting nicely...." )
550553 await self .close ()
0 commit comments