From c67be6b1f74b88963c042fafe233c2923e9d1ced Mon Sep 17 00:00:00 2001 From: Fredrik Erlandsson Date: Thu, 29 Aug 2024 09:18:15 +0200 Subject: [PATCH] Fix Skyfi: add ClientResponse error handling, pass must be first parameter (#24) * add ClientResponse error handling * set pass as first parameter --- pydaikin/daikin_base.py | 18 +++++++++++++----- pydaikin/daikin_skyfi.py | 4 ++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pydaikin/daikin_base.py b/pydaikin/daikin_base.py index 69824d4..441aa13 100644 --- a/pydaikin/daikin_base.py +++ b/pydaikin/daikin_base.py @@ -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, @@ -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), @@ -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): diff --git a/pydaikin/daikin_skyfi.py b/pydaikin/daikin_skyfi.py index c8e0d72..4a72cbf 100644 --- a/pydaikin/daikin_skyfi.py +++ b/pydaikin/daikin_skyfi.py @@ -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):