Skip to content

Commit e473f1e

Browse files
authored
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
1 parent 1d709b6 commit e473f1e

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

pymyq/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""Define a version constant."""
2-
__version__ = "3.1.0"
2+
__version__ = "3.1.1"

pymyq/api.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,12 @@ async def update_device_info(self) -> None:
578578
self.last_state_update = datetime.utcnow()
579579

580580

581-
async def login(username: str, password: str, websession: ClientSession = None) -> API:
581+
async def login(
582+
username: str,
583+
password: str,
584+
websession: ClientSession = None,
585+
auth_only: bool = False,
586+
) -> API:
582587
"""Log in to the API."""
583588

584589
# Set the user agent in the headers.
@@ -593,8 +598,9 @@ async def login(username: str, password: str, websession: ClientSession = None)
593598
_LOGGER.error("Authentication failed: %s", str(err))
594599
raise err
595600

596-
# Retrieve and store initial set of devices:
597-
_LOGGER.debug("Retrieving MyQ information")
598-
await api.update_device_info()
601+
if not auth_only:
602+
# Retrieve and store initial set of devices:
603+
_LOGGER.debug("Retrieving MyQ information")
604+
await api.update_device_info()
599605

600606
return api

pymyq/request.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ async def _send_request(
112112
last_error = ""
113113

114114
for attempt in range(DEFAULT_REQUEST_RETRIES):
115-
if self._useragent is None:
116-
await self._get_useragent()
117-
118115
if self._useragent is not None and self._useragent != "":
119116
headers.update({"User-Agent": self._useragent})
120117

@@ -174,9 +171,17 @@ async def _send_request(
174171
await self._get_useragent()
175172

176173
except ClientError as err:
177-
_LOGGER.debug(
178-
"Attempt %s request failed with exception: %s", attempt, str(err)
179-
)
174+
if err.errno == 54 and attempt == 0:
175+
_LOGGER.debug(
176+
"Received error status 54, connection reset. Will refresh user agent."
177+
)
178+
await self._get_useragent()
179+
else:
180+
_LOGGER.debug(
181+
"Attempt %s request failed with exception: %s",
182+
attempt,
183+
str(err),
184+
)
180185
last_status = ""
181186
last_error = str(err)
182187
resp_exc = err

0 commit comments

Comments
 (0)