Skip to content

Commit

Permalink
Fix Skyfi: add ClientResponse error handling, pass must be first para…
Browse files Browse the repository at this point in the history
…meter (#24)

* add ClientResponse error handling

* set pass as first parameter
  • Loading branch information
fredrike authored Aug 29, 2024
1 parent ff1cdf1 commit c67be6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions pydaikin/daikin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
from urllib.parse import unquote

from aiohttp import ClientSession
from aiohttp.client_exceptions import ClientOSError, ServerDisconnectedError
from aiohttp.web_exceptions import HTTPError, HTTPForbidden
from aiohttp.client_exceptions import (
ClientOSError,
ClientResponseError,
ServerDisconnectedError,
)
from aiohttp.web_exceptions import HTTPForbidden
from tenacity import (
before_sleep_log,
retry,
Expand Down Expand Up @@ -129,8 +133,9 @@ async def init(self):
stop=stop_after_attempt(3),
retry=retry_if_exception_type(
(
ServerDisconnectedError,
ClientOSError,
ClientResponseError,
ServerDisconnectedError,
)
),
before_sleep=before_sleep_log(_LOGGER, logging.DEBUG),
Expand Down Expand Up @@ -166,9 +171,12 @@ async def _get_resource(self, path: str, params: Optional[dict] = None):
{}
) # return an empty dict to indicate successful connection but bad data
if response.status != 200:
raise HTTPError(
reason=f"Unexpected HTTP status code {response.status} for {response.url}"
_LOGGER.debug(
"Unexpected HTTP status code %s for %s",
response.status,
response.url,
)
response.raise_for_status()
return self.parse_response(await response.text())

async def update_status(self, resources=None):
Expand Down
4 changes: 2 additions & 2 deletions pydaikin/daikin_skyfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ async def _get_resource(self, path: str, params: dict | None = None):
"""Make the http request."""
if params is None:
params = {}
params["pass"] = self._password

# ensure password is the first parameter
params = {**{"pass": self._password}, **params}
return await super()._get_resource(path, params)

def represent(self, key):
Expand Down

0 comments on commit c67be6b

Please sign in to comment.