Skip to content

Commit 6d67f93

Browse files
authored
Merge pull request #11 from rlippmann/1.2.8-fixes
1.2.8
2 parents ae3c466 + aed28b8 commit 6d67f93

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.2.8 (2024-03-07)
2+
3+
* add more detail to "invalid sync check" error logging
4+
* don't exit sync check task on service temporarily unavailable or invalid login
5+
* don't use empty site id for logins
6+
17
## 1.2.7 (2024-02-23)
28

39
* catch site is None on logout to prevent "have you logged in" errors

pyadtpulse/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Constants for pyadtpulse."""
22

3-
__version__ = "1.2.7"
3+
__version__ = "1.2.8"
44

55
DEFAULT_API_HOST = "https://portal.adtpulse.com"
66
API_HOST_CA = "https://portal-ca.adtpulse.com" # Canada

pyadtpulse/pulse_connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ async def async_do_login_query(
215215
data = {
216216
"usernameForm": self._authentication_properties.username,
217217
"passwordForm": self._authentication_properties.password,
218-
"networkid": self._authentication_properties.site_id,
219218
"fingerprint": self._authentication_properties.fingerprint,
220219
}
220+
if self._authentication_properties.site_id:
221+
data["networkid"] = self._authentication_properties.site_id
221222
await self._login_backoff.wait_for_backoff()
222223
try:
223224
response = await self.async_query(

pyadtpulse/pulse_query_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def _handle_http_errors(
109109
Raises:
110110
PulseServerConnectionError: If the server returns an error code.
111111
PulseServiceTemporarilyUnavailableError: If the server returns a
112-
Retry-After header."""
112+
HTTP status code of 429 or 503.
113+
"""
113114

114115
def get_retry_after(retry_after: str) -> int | None:
115116
"""
@@ -212,7 +213,7 @@ async def async_query(
212213
Raises:
213214
PulseClientConnectionError: If the client cannot connect
214215
PulseServerConnectionError: If there is a server error
215-
PulseServiceTemporarilyUnavailableError: If the server returns a Retry-After header
216+
PulseServiceTemporarilyUnavailableError: If the server returns an HTTP status code of 429 or 503
216217
PulseNotLoggedInError: if not logged in and task is waiting for longer than
217218
ADT_DEFAULT_LOGIN_TIMEOUT seconds
218219
"""

pyadtpulse/pyadtpulse_async.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,18 @@ def check_sync_check_response() -> bool:
443443
return False
444444
pattern = r"\d+[-]\d+[-]\d+"
445445
if not re.match(pattern, response_text):
446-
LOG.warning(
447-
"Unexpected sync check format",
448-
)
449-
self._pulse_connection.check_login_errors((code, response_text, url))
446+
warning_msg = "Unexpected sync check format"
447+
try:
448+
self._pulse_connection.check_login_errors(
449+
(code, response_text, url)
450+
)
451+
except Exception as ex:
452+
warning_msg += f": {ex}"
453+
raise
454+
else:
455+
warning_msg += ": skipping"
456+
finally:
457+
LOG.warning(warning_msg)
450458
return False
451459
split_text = response_text.split("-")
452460
if int(split_text[0]) > 9 or int(split_text[1]) > 9:
@@ -523,17 +531,17 @@ async def shutdown_task(ex: Exception):
523531
msg = ", ignoring..."
524532
LOG.debug("Pulse sync check query failed due to %s%s", e, msg)
525533
continue
526-
except (
527-
PulseServiceTemporarilyUnavailableError,
528-
PulseNotLoggedInError,
529-
) as e:
530-
if isinstance(e, PulseServiceTemporarilyUnavailableError):
531-
status = "temporarily unavailable"
532-
else:
533-
status = "not logged in"
534-
LOG.error("Pulse service %s, ending %s task", status, task_name)
535-
await shutdown_task(e)
536-
return
534+
except PulseServiceTemporarilyUnavailableError as e:
535+
LOG.error("Pulse sync check query failed due to %s", e)
536+
self._set_update_exception(e)
537+
continue
538+
except PulseNotLoggedInError:
539+
LOG.info(
540+
"Pulse sync check query failed due to not logged in, relogging in..."
541+
)
542+
await self._pulse_connection.quick_logout()
543+
await self._login_looped(task_name)
544+
continue
537545
if not handle_response(
538546
code, url, logging.WARNING, "Error querying ADT sync"
539547
):
@@ -548,7 +556,9 @@ async def shutdown_task(ex: Exception):
548556
else:
549557
have_updates = check_sync_check_response()
550558
except PulseNotLoggedInError:
551-
LOG.info("Pulse sync check indicates logged out, re-logging in....")
559+
LOG.info(
560+
"Pulse sync check text indicates logged out, re-logging in...."
561+
)
552562
await self._pulse_connection.quick_logout()
553563
await self._login_looped(task_name)
554564
except (

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pyadtpulse"
3-
version = "1.2.7"
3+
version = "1.2.8"
44
description = "Python interface for ADT Pulse security systems"
55
authors = ["Ryan Snodgrass"]
66
maintainers = ["Robert Lippmann"]

0 commit comments

Comments
 (0)