aioamazondevices 1.1.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: aioamazondevices
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: Python library to control Amazon devices
5
5
  License: Apache-2.0
6
6
  Author: Simone Chemelli
@@ -69,12 +69,22 @@ Install this via pip (or your favourite package manager):
69
69
 
70
70
  `pip install aioamazondevices`
71
71
 
72
- ## Usage
72
+ ## Test
73
73
 
74
- Start by importing it:
74
+ Test the library with:
75
75
 
76
- ```python
77
- import aioamazondevices
76
+ `python library_test.py`
77
+
78
+ The script accept command line arguments or a library_test.json config file:
79
+
80
+ ```json
81
+ {
82
+ "country": "IT",
83
+ "email": "<my_address@gmail.com>",
84
+ "password": "<my_password>",
85
+ "login_data_file": "out/login_data.json",
86
+ "save_raw_data": "True"
87
+ }
78
88
  ```
79
89
 
80
90
  ## Contributors ✨
@@ -41,12 +41,22 @@ Install this via pip (or your favourite package manager):
41
41
 
42
42
  `pip install aioamazondevices`
43
43
 
44
- ## Usage
44
+ ## Test
45
45
 
46
- Start by importing it:
46
+ Test the library with:
47
47
 
48
- ```python
49
- import aioamazondevices
48
+ `python library_test.py`
49
+
50
+ The script accept command line arguments or a library_test.json config file:
51
+
52
+ ```json
53
+ {
54
+ "country": "IT",
55
+ "email": "<my_address@gmail.com>",
56
+ "password": "<my_password>",
57
+ "login_data_file": "out/login_data.json",
58
+ "save_raw_data": "True"
59
+ }
50
60
  ```
51
61
 
52
62
  ## Contributors ✨
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "aioamazondevices"
3
- version = "1.1.0"
3
+ version = "1.2.0"
4
4
  description = "Python library to control Amazon devices"
5
5
  authors = ["Simone Chemelli <simone.chemelli@gmail.com>"]
6
6
  license = "Apache-2.0"
@@ -1,6 +1,6 @@
1
1
  """aioamazondevices library."""
2
2
 
3
- __version__ = "1.1.0"
3
+ __version__ = "1.2.0"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
@@ -340,8 +340,8 @@ class AmazonEchoApi:
340
340
 
341
341
  register_url = f"https://api.amazon.{self._domain}/auth/register"
342
342
  _, resp = await self._session_request(
343
- "POST",
344
- register_url,
343
+ method="POST",
344
+ url=register_url,
345
345
  input_data=body,
346
346
  json_data=True,
347
347
  )
@@ -404,7 +404,7 @@ class AmazonEchoApi:
404
404
  _LOGGER.debug("Build oauth URL")
405
405
  login_url = self._build_oauth_url(code_verifier, client_id)
406
406
 
407
- login_soup, _ = await self._session_request("GET", login_url)
407
+ login_soup, _ = await self._session_request(method="GET", url=login_url)
408
408
  login_method, login_url = self._get_request_from_soup(login_soup)
409
409
  login_inputs = self._get_inputs_from_soup(login_soup)
410
410
  login_inputs["email"] = self._login_email
@@ -412,9 +412,9 @@ class AmazonEchoApi:
412
412
 
413
413
  _LOGGER.debug("Register at %s", login_url)
414
414
  login_soup, _ = await self._session_request(
415
- login_method,
416
- login_url,
417
- login_inputs,
415
+ method=login_method,
416
+ url=login_url,
417
+ input_data=login_inputs,
418
418
  )
419
419
 
420
420
  if not login_soup.find("input", id="auth-mfa-otpcode"):
@@ -431,9 +431,9 @@ class AmazonEchoApi:
431
431
  login_inputs["rememberDevice"] = "false"
432
432
 
433
433
  login_soup, login_resp = await self._session_request(
434
- login_method,
435
- login_url,
436
- login_inputs,
434
+ method=login_method,
435
+ url=login_url,
436
+ input_data=login_inputs,
437
437
  )
438
438
 
439
439
  authcode_url = None
@@ -465,7 +465,7 @@ class AmazonEchoApi:
465
465
  if not self._login_stored_data:
466
466
  _LOGGER.debug(
467
467
  "Cannot find previous login data,\
468
- use login_interactive() method instead",
468
+ use login_mode_interactive() method instead",
469
469
  )
470
470
  raise WrongMethod
471
471
 
@@ -491,8 +491,8 @@ class AmazonEchoApi:
491
491
  devices: dict[str, Any] = {}
492
492
  for key in URI_QUERIES:
493
493
  _, raw_resp = await self._session_request(
494
- "GET",
495
- f"https://alexa.amazon.{self._domain}{URI_QUERIES[key]}",
494
+ method="GET",
495
+ url=f"https://alexa.amazon.{self._domain}{URI_QUERIES[key]}",
496
496
  )
497
497
  _LOGGER.debug("Response URL: %s", raw_resp.url)
498
498
  response_code = raw_resp.status_code
@@ -536,3 +536,25 @@ class AmazonEchoApi:
536
536
  )
537
537
 
538
538
  return final_devices_list
539
+
540
+ async def auth_check_status(self) -> bool:
541
+ """Check AUTH status."""
542
+ _, raw_resp = await self._session_request(
543
+ method="GET",
544
+ url=f"https://alexa.amazon.{self._domain}/api/bootstrap?version=0",
545
+ )
546
+ if raw_resp.status_code != HTTPStatus.OK:
547
+ _LOGGER.debug(
548
+ "Session not authenticated: reply error %s",
549
+ raw_resp.status_code,
550
+ )
551
+ return False
552
+
553
+ resp_json = raw_resp.json()
554
+ if not (authentication := resp_json.get("authentication")):
555
+ _LOGGER.debug('Session not authenticated: reply missing "authentication"')
556
+ return False
557
+
558
+ authenticated = authentication.get("authenticated")
559
+ _LOGGER.debug("Session authenticated: %s", authenticated)
560
+ return bool(authenticated)