11#!/usr/bin/env python
22"""Sample client for using pyadtpulse."""
33
4+ import sys
5+ import json
6+ import asyncio
47import logging
58import argparse
6- import asyncio
7- import json
8- import sys
9+ from time import time , sleep
910from pprint import pprint
10- from time import sleep , time
1111
1212from pyadtpulse import PyADTPulse
13+ from pyadtpulse .site import ADTPulseSite
1314from pyadtpulse .const import (
14- ADT_DEFAULT_KEEPALIVE_INTERVAL ,
15- ADT_DEFAULT_POLL_INTERVAL ,
16- ADT_DEFAULT_RELOGIN_INTERVAL ,
1715 API_HOST_CA ,
1816 DEFAULT_API_HOST ,
17+ ADT_DEFAULT_POLL_INTERVAL ,
18+ ADT_DEFAULT_RELOGIN_INTERVAL ,
19+ ADT_DEFAULT_KEEPALIVE_INTERVAL ,
1920)
2021from pyadtpulse .exceptions import (
21- PulseAuthenticationError ,
22- PulseClientConnectionError ,
22+ PulseLoginException ,
2323 PulseConnectionError ,
24+ PulseAuthenticationError ,
2425 PulseGatewayOfflineError ,
25- PulseLoginException ,
26+ PulseClientConnectionError ,
2627 PulseServerConnectionError ,
2728 PulseServiceTemporarilyUnavailableError ,
2829)
2930from pyadtpulse .pyadtpulse_async import PyADTPulseAsync
30- from pyadtpulse .site import ADTPulseSite
3131
3232USER = "adtpulse_user"
3333PASSWD = "adtpulse_password"
@@ -82,10 +82,12 @@ def setup_logger(level: int):
8282
8383
8484def handle_args () -> argparse .Namespace :
85- """Handle program arguments using argparse.
85+ """
86+ Handle program arguments using argparse.
8687
8788 Returns:
8889 argparse.Namespace: Parsed command-line arguments.
90+
8991 """
9092 parser = argparse .ArgumentParser (description = "ADT Pulse example client" )
9193 parser .add_argument ("json_file" , nargs = "?" , help = "JSON file containing parameters" )
@@ -217,14 +219,16 @@ def handle_args() -> argparse.Namespace:
217219
218220
219221def load_parameters_from_json (json_file : str ) -> dict | None :
220- """Load parameters from a JSON file.
222+ """
223+ Load parameters from a JSON file.
221224
222225 Args:
223226 json_file (str): Path to the JSON file.
224227
225228 Returns:
226229 Optional[Dict]: Loaded parameters as a dictionary,
227230 or None if there was an error.
231+
228232 """
229233 try :
230234 with open (json_file , encoding = "utf-8" ) as file :
@@ -268,10 +272,12 @@ def load_parameters_from_json(json_file: str) -> dict | None:
268272
269273
270274def print_site (site : ADTPulseSite ) -> None :
271- """Print site information.
275+ """
276+ Print site information.
272277
273278 Args:
274279 site (ADTPulseSite): The site to display
280+
275281 """
276282 print (f"Site: { site .name } (id={ site .id } )" )
277283 print ("Alarm panel: " )
@@ -281,7 +287,8 @@ def print_site(site: ADTPulseSite) -> None:
281287
282288
283289def check_updates (site : ADTPulseSite , adt : PyADTPulse , run_alarm_test : bool ) -> bool :
284- """Check a site for updates and print details.
290+ """
291+ Check a site for updates and print details.
285292
286293 We don't really need to do this anymore, as the data will be
287294 updated in the background
@@ -292,6 +299,7 @@ def check_updates(site: ADTPulseSite, adt: PyADTPulse, run_alarm_test: bool) ->
292299 test_alarm: bool: sleep a bit if testing alarm
293300
294301 Returns: bool: True if update successful
302+
295303 """
296304 if run_alarm_test :
297305 while (
@@ -311,12 +319,14 @@ def check_updates(site: ADTPulseSite, adt: PyADTPulse, run_alarm_test: bool) ->
311319
312320
313321def test_alarm (site : ADTPulseSite , adt : PyADTPulse ) -> None :
314- """Test alarm functions.
322+ """
323+ Test alarm functions.
315324
316325 Args:
317326 site (ADTPulseSite): site to test
318327 adt (PyADTPulse): ADT Pulse connection objecct
319328 sleep_interval (int): length to sleep between tests
329+
320330 """
321331 print ("Arming alarm stay" )
322332 if site .arm_home ():
@@ -382,7 +392,8 @@ def sync_example(
382392 relogin_interval : int ,
383393 detailed_debug_logging : bool ,
384394) -> None :
385- """Run example of sync pyadtpulse calls.
395+ """
396+ Run example of sync pyadtpulse calls.
386397
387398 Args:
388399 username (str): Pulse username
@@ -394,6 +405,7 @@ def sync_example(
394405 keepalive_interval (int): keepalive interval in minutes
395406 relogin_interval (int): relogin interval in minutes
396407 detailed_debug_logging (bool): True to enable detailed debug logging
408+
397409 """
398410 while True :
399411 try :
@@ -497,11 +509,13 @@ def sync_example(
497509
498510
499511async def async_test_alarm (adt : PyADTPulse ) -> None :
500- """Test alarm functions.
512+ """
513+ Test alarm functions.
501514
502515 Args:
503516 site (ADTPulseSite): site to test
504517 adt (PyADTPulse): ADT Pulse connection objecct
518+
505519 """
506520 print ("Arming alarm stay" )
507521 if await adt .site .async_arm_home ():
@@ -619,7 +633,8 @@ async def async_example(
619633 relogin_interval : int ,
620634 detailed_debug_logging : bool ,
621635) -> None :
622- """Run example of pytadtpulse async usage.
636+ """
637+ Run example of pytadtpulse async usage.
623638
624639 Args:
625640 username (str): Pulse username
@@ -631,6 +646,7 @@ async def async_example(
631646 keepalive_interval (int): keepalive interval in minutes
632647 relogin_interval (int): relogin interval in minutes
633648 detailed_debug_logging (bool): enable detailed debug logging
649+
634650 """
635651 adt = PyADTPulseAsync (
636652 username ,
0 commit comments