Skip to content

Commit

Permalink
Changed: tried to fix local api
Browse files Browse the repository at this point in the history
  • Loading branch information
ualex73 committed Aug 29, 2023
1 parent cd0cdec commit 7944d23
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
52 changes: 33 additions & 19 deletions goslideapi/goslideapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,12 @@ async def household_set(self, name, address, lat, lon):
class GoSlideLocal:
"""API Wrapper for the Go Slide devices, local connectivity."""

def __init__(self, timeout=DEFAULT_TIMEOUT, authexception=True):
def __init__(self, timeout=DEFAULT_TIMEOUT, authexception=True, apiversion=1):
"""Create the object with required parameters."""
self._timeout = timeout
self._cnoncecount = 0
self._authexception = authexception
self._apiversion = apiversion
self._cnoncecount = 0
self._requestcount = 0
self._slides = {}

Expand Down Expand Up @@ -537,6 +538,7 @@ async def _dorequest(self, reqtype, url, digestauth=None, data=None):
jsondata = None

return resp.status, jsondata

if resp.status == 401:

if "WWW-Authenticate" in resp.headers:
Expand Down Expand Up @@ -590,28 +592,40 @@ async def _request(self, hostname, password, reqtype, uri, data=None):
# First request, should return a 401 error
respstatus, resptext = await self._dorequest(reqtype, url)

# Only a 401 response is correct
if respstatus == 401:

# The resptext contains the WWW-Authentication header
auth = self._make_digest_auth("user", password, reqtype, uri, resptext)

respstatus, resptext = await self._dorequest(
reqtype, url, digestauth=auth, data=data
)

# Default is version 1, when we do WWW-Authentication
if self._apiversion == 1:

# Only a 401 response is correct
if respstatus == 401:

# The resptext contains the WWW-Authentication header
auth = self._make_digest_auth("user", password, reqtype, uri, resptext)

respstatus, resptext = await self._dorequest(
reqtype, url, digestauth=auth, data=data
)

if respstatus == 200:
return resptext

# Anything else is an error
_LOGGER.error(
"Failed request with Local API Digest Authentication challenge. HTTPCode=%s",
respstatus,
)
else:
# We expected a 401 Digest Auth here
_LOGGER.error(
"Failed request with Local API. Received HTTPCode=%s, expected HTTPCode=401",
respstatus,
)
else:
if respstatus == 200:
return resptext

# Anything else is an error
_LOGGER.error(
"Failed request with Local API Digest Authentication challenge. HTTPCode=%s",
respstatus,
)
else:
# We expected a 401 Digest Auth here
_LOGGER.error(
"Failed request with Local API. Received HTTPCode=%s, expected HTTPCode=401",
"Failed request with Local API. HTTPCode=%s",
respstatus,
)

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setuptools.setup(
name='goslide-api',
version='0.6.4',
version='0.6.5',
url='https://github.com/ualex73/goslide-api',
license='Apache License 2.0',
author='Alexander Kuiper',
Expand All @@ -24,6 +24,8 @@
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
],
Expand Down

0 comments on commit 7944d23

Please sign in to comment.