aioamazondevices 0.7.1__py3-none-any.whl → 0.7.3__py3-none-any.whl

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
  """aioamazondevices library."""
2
2
 
3
- __version__ = "0.7.1"
3
+ __version__ = "0.7.3"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
aioamazondevices/api.py CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import base64
4
4
  import hashlib
5
+ import json
5
6
  import mimetypes
6
7
  import secrets
7
8
  import uuid
@@ -9,7 +10,7 @@ from dataclasses import dataclass
9
10
  from datetime import UTC, datetime, timedelta
10
11
  from http import HTTPStatus
11
12
  from pathlib import Path
12
- from typing import Any
13
+ from typing import Any, cast
13
14
  from urllib.parse import parse_qs, urlencode
14
15
 
15
16
  import orjson
@@ -30,6 +31,7 @@ from .const import (
30
31
  DOMAIN_BY_COUNTRY,
31
32
  HTML_EXTENSION,
32
33
  JSON_EXTENSION,
34
+ SAVE_PATH,
33
35
  URI_QUERIES,
34
36
  )
35
37
  from .exceptions import CannotAuthenticate, CannotRegisterDevice
@@ -78,10 +80,24 @@ class AmazonEchoApi:
78
80
  self._cookies = self._build_init_cookies()
79
81
  self._headers = DEFAULT_HEADERS
80
82
  self._save_html = save_html
81
- self._serial = uuid.uuid4().hex.upper()
83
+ self._serial = self._serial_number()
82
84
 
83
85
  self.session: AsyncClient
84
86
 
87
+ def _serial_number(self) -> str:
88
+ """Get or calculate device serial number."""
89
+ fullpath = Path(SAVE_PATH, "login_data.json")
90
+ if not fullpath.exists():
91
+ # Create a new serial number
92
+ _LOGGER.debug("Cannot find previous login data, creating new serial number")
93
+ return uuid.uuid4().hex.upper()
94
+
95
+ with Path.open(fullpath, "rb") as file:
96
+ data = json.load(file)
97
+
98
+ _LOGGER.debug("Found previous login data, loading serial number")
99
+ return cast(str, data["device_info"]["device_serial_number"])
100
+
85
101
  def _build_init_cookies(self) -> dict[str, str]:
86
102
  """Build initial cookies to prevent captcha in most cases."""
87
103
  token_bytes = secrets.token_bytes(313)
@@ -216,7 +232,7 @@ class AmazonEchoApi:
216
232
  raw_data: str | dict,
217
233
  url: str,
218
234
  extension: str = HTML_EXTENSION,
219
- output_path: str = "out",
235
+ output_path: str = SAVE_PATH,
220
236
  ) -> None:
221
237
  """Save response data to disk."""
222
238
  if not self._save_html:
aioamazondevices/const.py CHANGED
@@ -53,5 +53,6 @@ AMAZON_DEVICE_TYPE = "A2IVLV5VM2W81"
53
53
  AMAZON_CLIENT_OS = "16.6"
54
54
 
55
55
  # File extensions
56
+ SAVE_PATH = "out"
56
57
  HTML_EXTENSION = ".html"
57
58
  JSON_EXTENSION = ".json"
@@ -1,15 +1,15 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aioamazondevices
3
- Version: 0.7.1
3
+ Version: 0.7.3
4
4
  Summary: Python library to control Amazon devices
5
5
  Home-page: https://github.com/chemelli74/aioamazondevices
6
- License: Apache Software License 2.0
6
+ License: Apache-2.0
7
7
  Author: Simone Chemelli
8
8
  Author-email: simone.chemelli@gmail.com
9
9
  Requires-Python: >=3.11,<4.0
10
10
  Classifier: Development Status :: 2 - Pre-Alpha
11
11
  Classifier: Intended Audience :: Developers
12
- Classifier: License :: Other/Proprietary License
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Natural Language :: English
14
14
  Classifier: Operating System :: OS Independent
15
15
  Classifier: Programming Language :: Python :: 3
@@ -0,0 +1,9 @@
1
+ aioamazondevices/__init__.py,sha256=43R_n8z8MnmFxV1nrDOdsTWDjs61LdB_GbYMBmN1YTU,276
2
+ aioamazondevices/api.py,sha256=3eagygo9Kx1Qx2v602wZW6MyCTuA5Tmq545TmGX6zWc,16518
3
+ aioamazondevices/const.py,sha256=BnA9rU9S9vH9mmmE-In443PECLUmGll9-iWu-oETo4s,1348
4
+ aioamazondevices/exceptions.py,sha256=yQ9nL4UwBdHNXvdRj8TRemed6PXBmExP8lbHaAp04vY,546
5
+ aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ aioamazondevices-0.7.3.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
7
+ aioamazondevices-0.7.3.dist-info/METADATA,sha256=u9bchAmH6hMggC3zHTUDMR7phel-64dmrv9ptUdp0vE,4752
8
+ aioamazondevices-0.7.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
9
+ aioamazondevices-0.7.3.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- aioamazondevices/__init__.py,sha256=IxGu-Lv8_pSEPCQnjhVi-_VdJGmh9WI0NOELkRSSVjQ,276
2
- aioamazondevices/api.py,sha256=3Gshun5XSEbD47aDs-hyQkZ_zVYuQ3OMwXIaZA13lmo,15902
3
- aioamazondevices/const.py,sha256=CQFuM-4gFrzveQcBMsH6noI8PN69J4ogV-P46uYhcTQ,1330
4
- aioamazondevices/exceptions.py,sha256=yQ9nL4UwBdHNXvdRj8TRemed6PXBmExP8lbHaAp04vY,546
5
- aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- aioamazondevices-0.7.1.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
7
- aioamazondevices-0.7.1.dist-info/METADATA,sha256=Eq-0torKLJNk79WSTqq2I4pnPqAM-VsQ3u8ibrVytUo,4755
8
- aioamazondevices-0.7.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
9
- aioamazondevices-0.7.1.dist-info/RECORD,,