From e473f1e94bf265b02c5e808276676c18a6c07f8a Mon Sep 17 00:00:00 2001 From: ehendrix23 Date: Mon, 9 Aug 2021 16:03:48 -0600 Subject: [PATCH] v3.1.1 (#117) * Check auth only for login * Update user agent on connection reset (54) * Only set user agent when error * Version 3.1.1 --- pymyq/__version__.py | 2 +- pymyq/api.py | 14 ++++++++++---- pymyq/request.py | 17 +++++++++++------ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/pymyq/__version__.py b/pymyq/__version__.py index ce40bae..16c73b7 100644 --- a/pymyq/__version__.py +++ b/pymyq/__version__.py @@ -1,2 +1,2 @@ """Define a version constant.""" -__version__ = "3.1.0" +__version__ = "3.1.1" diff --git a/pymyq/api.py b/pymyq/api.py index bb7991b..2cbc770 100644 --- a/pymyq/api.py +++ b/pymyq/api.py @@ -578,7 +578,12 @@ async def update_device_info(self) -> None: self.last_state_update = datetime.utcnow() -async def login(username: str, password: str, websession: ClientSession = None) -> API: +async def login( + username: str, + password: str, + websession: ClientSession = None, + auth_only: bool = False, +) -> API: """Log in to the API.""" # Set the user agent in the headers. @@ -593,8 +598,9 @@ async def login(username: str, password: str, websession: ClientSession = None) _LOGGER.error("Authentication failed: %s", str(err)) raise err - # Retrieve and store initial set of devices: - _LOGGER.debug("Retrieving MyQ information") - await api.update_device_info() + if not auth_only: + # Retrieve and store initial set of devices: + _LOGGER.debug("Retrieving MyQ information") + await api.update_device_info() return api diff --git a/pymyq/request.py b/pymyq/request.py index 7a581bc..7c5a7fe 100644 --- a/pymyq/request.py +++ b/pymyq/request.py @@ -112,9 +112,6 @@ async def _send_request( last_error = "" for attempt in range(DEFAULT_REQUEST_RETRIES): - if self._useragent is None: - await self._get_useragent() - if self._useragent is not None and self._useragent != "": headers.update({"User-Agent": self._useragent}) @@ -174,9 +171,17 @@ async def _send_request( await self._get_useragent() except ClientError as err: - _LOGGER.debug( - "Attempt %s request failed with exception: %s", attempt, str(err) - ) + if err.errno == 54 and attempt == 0: + _LOGGER.debug( + "Received error status 54, connection reset. Will refresh user agent." + ) + await self._get_useragent() + else: + _LOGGER.debug( + "Attempt %s request failed with exception: %s", + attempt, + str(err), + ) last_status = "" last_error = str(err) resp_exc = err