Skip to content

Commit

Permalink
v3.1.1 (#117)
Browse files Browse the repository at this point in the history
* Check auth only for login

* Update user agent on connection reset (54)

* Only set user agent when error

* Version 3.1.1
  • Loading branch information
ehendrix23 authored Aug 9, 2021
1 parent 1d709b6 commit e473f1e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pymyq/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Define a version constant."""
__version__ = "3.1.0"
__version__ = "3.1.1"
14 changes: 10 additions & 4 deletions pymyq/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
17 changes: 11 additions & 6 deletions pymyq/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e473f1e

Please sign in to comment.