@@ -433,7 +433,7 @@ async def household_set(self, name, address, lat, lon):
433
433
class GoSlideLocal :
434
434
"""API Wrapper for the Go Slide devices, local connectivity."""
435
435
436
- def __init__ (self , timeout = DEFAULT_TIMEOUT , authexception = True , apiversion = 1 ):
436
+ def __init__ (self , timeout = DEFAULT_TIMEOUT , authexception = True , apiversion = 2 ):
437
437
"""Create the object with required parameters."""
438
438
self ._timeout = timeout
439
439
self ._authexception = authexception
@@ -589,13 +589,16 @@ async def _request(self, hostname, password, reqtype, uri, data=None):
589
589
# format URL with hostname/ip and uri value
590
590
url = "http://{}{}" .format (hostname , uri )
591
591
592
- # First request, should return a 401 error
593
- respstatus , resptext = await self . _dorequest ( reqtype , url )
592
+ # First request, should return a 401 error for v1
593
+ # First request is not required for v2
594
594
595
595
# Default is version 1, when we do WWW-Authentication
596
596
if self ._apiversion == 1 :
597
597
598
- # Only a 401 response is correct
598
+ #do request to obtain a WWW-authentication header:
599
+ respstatus , resptext = await self ._dorequest (reqtype , url )
600
+
601
+ #Only a 401 response is correct
599
602
if respstatus == 401 :
600
603
601
604
# The resptext contains the WWW-Authentication header
@@ -616,17 +619,28 @@ async def _request(self, hostname, password, reqtype, uri, data=None):
616
619
else :
617
620
# We expected a 401 Digest Auth here
618
621
_LOGGER .error (
619
- "Failed request with Local API. Received HTTPCode=%s, expected HTTPCode=401" ,
622
+ "Failed request with Local API v1 . Received HTTPCode=%s, expected HTTPCode=401. Maybe try switching to v2? " ,
620
623
respstatus ,
621
624
)
622
- else :
623
- if respstatus == 200 :
624
- return resptext
625
625
626
- # Anything else is an error
626
+ elif self ._apiversion == 2 :
627
+
628
+ respstatus , resptext = await self ._dorequest (
629
+ reqtype , url , data = data
630
+ )
631
+
632
+ if respstatus == 200 :
633
+ return resptext
634
+
635
+ # Anything else is an error
636
+ _LOGGER .error (
637
+ "Failed request Local API v2. HTTPCode=%s" ,
638
+ respstatus ,
639
+ )
640
+
641
+ else :
627
642
_LOGGER .error (
628
- "Failed request with Local API. HTTPCode=%s" ,
629
- respstatus ,
643
+ "Only v1 and v2 is supported." ,
630
644
)
631
645
632
646
return None
0 commit comments