aioamazondevices 0.7.1__tar.gz → 0.7.2__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.
- {aioamazondevices-0.7.1 → aioamazondevices-0.7.2}/PKG-INFO +1 -1
- {aioamazondevices-0.7.1 → aioamazondevices-0.7.2}/pyproject.toml +1 -1
- {aioamazondevices-0.7.1 → aioamazondevices-0.7.2}/src/aioamazondevices/__init__.py +1 -1
- {aioamazondevices-0.7.1 → aioamazondevices-0.7.2}/src/aioamazondevices/api.py +19 -3
- {aioamazondevices-0.7.1 → aioamazondevices-0.7.2}/src/aioamazondevices/const.py +1 -0
- {aioamazondevices-0.7.1 → aioamazondevices-0.7.2}/LICENSE +0 -0
- {aioamazondevices-0.7.1 → aioamazondevices-0.7.2}/README.md +0 -0
- {aioamazondevices-0.7.1 → aioamazondevices-0.7.2}/src/aioamazondevices/exceptions.py +0 -0
- {aioamazondevices-0.7.1 → aioamazondevices-0.7.2}/src/aioamazondevices/py.typed +0 -0
@@ -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 =
|
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 =
|
235
|
+
output_path: str = SAVE_PATH,
|
220
236
|
) -> None:
|
221
237
|
"""Save response data to disk."""
|
222
238
|
if not self._save_html:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|