aioamazondevices 3.1.23__py3-none-any.whl → 3.2.1__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.
- aioamazondevices/__init__.py +1 -1
- aioamazondevices/api.py +48 -1
- aioamazondevices/const.py +1 -0
- aioamazondevices/exceptions.py +4 -0
- {aioamazondevices-3.1.23.dist-info → aioamazondevices-3.2.1.dist-info}/METADATA +1 -1
- aioamazondevices-3.2.1.dist-info/RECORD +11 -0
- aioamazondevices-3.1.23.dist-info/RECORD +0 -11
- {aioamazondevices-3.1.23.dist-info → aioamazondevices-3.2.1.dist-info}/LICENSE +0 -0
- {aioamazondevices-3.1.23.dist-info → aioamazondevices-3.2.1.dist-info}/WHEEL +0 -0
aioamazondevices/__init__.py
CHANGED
aioamazondevices/api.py
CHANGED
@@ -32,6 +32,7 @@ from .const import (
|
|
32
32
|
AMAZON_DEVICE_TYPE,
|
33
33
|
BIN_EXTENSION,
|
34
34
|
CSRF_COOKIE,
|
35
|
+
DEFAULT_AGENT,
|
35
36
|
DEFAULT_ASSOC_HANDLE,
|
36
37
|
DEFAULT_HEADERS,
|
37
38
|
DEVICE_TO_IGNORE,
|
@@ -56,6 +57,7 @@ from .exceptions import (
|
|
56
57
|
CannotConnect,
|
57
58
|
CannotRegisterDevice,
|
58
59
|
CannotRetrieveData,
|
60
|
+
WrongCountry,
|
59
61
|
WrongMethod,
|
60
62
|
)
|
61
63
|
from .utils import obfuscate_email, scrub_fields
|
@@ -160,7 +162,17 @@ class AmazonEchoApi:
|
|
160
162
|
if not self._login_stored_data:
|
161
163
|
return {}
|
162
164
|
|
163
|
-
|
165
|
+
website_cookies: dict[str, Any] = self._login_stored_data["website_cookies"]
|
166
|
+
website_cookies.update(
|
167
|
+
{
|
168
|
+
"session-token": self._login_stored_data["store_authentication_cookie"][
|
169
|
+
"cookie"
|
170
|
+
]
|
171
|
+
}
|
172
|
+
)
|
173
|
+
website_cookies.update({"lc-acbit": self._language})
|
174
|
+
|
175
|
+
return website_cookies
|
164
176
|
|
165
177
|
def _serial_number(self) -> str:
|
166
178
|
"""Get or calculate device serial number."""
|
@@ -324,6 +336,7 @@ class AmazonEchoApi:
|
|
324
336
|
url: str,
|
325
337
|
input_data: dict[str, Any] | None = None,
|
326
338
|
json_data: bool = False,
|
339
|
+
amazon_user_agent: bool = True,
|
327
340
|
) -> tuple[BeautifulSoup, ClientResponse]:
|
328
341
|
"""Return request response context data."""
|
329
342
|
_LOGGER.debug(
|
@@ -336,6 +349,9 @@ class AmazonEchoApi:
|
|
336
349
|
|
337
350
|
headers = DEFAULT_HEADERS
|
338
351
|
headers.update({"Accept-Language": self._language})
|
352
|
+
if not amazon_user_agent:
|
353
|
+
_LOGGER.debug("Changing User-Agent to %s", DEFAULT_AGENT)
|
354
|
+
headers.update({"User-Agent": DEFAULT_AGENT})
|
339
355
|
if self._csrf_cookie and CSRF_COOKIE not in headers:
|
340
356
|
csrf = {CSRF_COOKIE: self._csrf_cookie}
|
341
357
|
_LOGGER.debug("Adding <%s> to headers", csrf)
|
@@ -525,11 +541,37 @@ class AmazonEchoApi:
|
|
525
541
|
await self._save_to_file(login_data, "login_data", JSON_EXTENSION)
|
526
542
|
return login_data
|
527
543
|
|
544
|
+
async def _check_country(self) -> None:
|
545
|
+
"""Check if user selected country matches Amazon account country."""
|
546
|
+
url = f"https://alexa.amazon.{self._domain}/api/users/me"
|
547
|
+
_, resp_me = await self._session_request(HTTPMethod.GET, url)
|
548
|
+
|
549
|
+
if resp_me.status != HTTPStatus.OK:
|
550
|
+
raise CannotAuthenticate
|
551
|
+
|
552
|
+
resp_me_json = await resp_me.json()
|
553
|
+
market = resp_me_json["marketPlaceDomainName"]
|
554
|
+
language = resp_me_json["marketPlaceLocale"]
|
555
|
+
|
556
|
+
_domain = f"https://www.amazon.{self._domain}"
|
557
|
+
|
558
|
+
if market != _domain or language != self._language:
|
559
|
+
_LOGGER.debug(
|
560
|
+
"Selected country <%s> doesn't matches Amazon account:\n%s\n vs \n%s",
|
561
|
+
self._login_country_code.upper(),
|
562
|
+
{"site ": _domain, "locale": self._language},
|
563
|
+
{"market": market, "locale": language},
|
564
|
+
)
|
565
|
+
raise WrongCountry
|
566
|
+
|
567
|
+
_LOGGER.debug("User selected country matches Amazon account one")
|
568
|
+
|
528
569
|
async def _get_devices_ids(self) -> list[dict[str, str]]:
|
529
570
|
"""Retrieve devices entityId and applianceId."""
|
530
571
|
_, raw_resp = await self._session_request(
|
531
572
|
"GET",
|
532
573
|
url=f"https://alexa.amazon.{self._domain}{URI_IDS}",
|
574
|
+
amazon_user_agent=False,
|
533
575
|
)
|
534
576
|
json_data = await raw_resp.json()
|
535
577
|
|
@@ -698,6 +740,9 @@ class AmazonEchoApi:
|
|
698
740
|
self._login_stored_data = register_device
|
699
741
|
|
700
742
|
_LOGGER.info("Register device: %s", scrub_fields(register_device))
|
743
|
+
|
744
|
+
await self._check_country()
|
745
|
+
|
701
746
|
return register_device
|
702
747
|
|
703
748
|
async def login_mode_stored_data(self) -> dict[str, Any]:
|
@@ -716,6 +761,8 @@ class AmazonEchoApi:
|
|
716
761
|
|
717
762
|
self._client_session()
|
718
763
|
|
764
|
+
await self._check_country()
|
765
|
+
|
719
766
|
return self._login_stored_data
|
720
767
|
|
721
768
|
async def close(self) -> None:
|
aioamazondevices/const.py
CHANGED
@@ -86,6 +86,7 @@ DEFAULT_HEADERS = {
|
|
86
86
|
"Accept-Encoding": "gzip",
|
87
87
|
"Connection": "keep-alive",
|
88
88
|
}
|
89
|
+
DEFAULT_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0" # noqa: E501
|
89
90
|
CSRF_COOKIE = "csrf"
|
90
91
|
|
91
92
|
NODE_DEVICES = "devices"
|
aioamazondevices/exceptions.py
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
aioamazondevices/__init__.py,sha256=ylzOup7JB2cQ19iiOzvj0UaBpJlY2v4hV0fxxJyVeqo,276
|
2
|
+
aioamazondevices/api.py,sha256=8wXIou_9WeFjbNS4_qPbQ8YFWUfN8EdIbivQ-UWSGDI,39218
|
3
|
+
aioamazondevices/const.py,sha256=q2TlD1O4jPtQ-hIxCCZuD-uoXCFNudF11JSjSC2hClY,8687
|
4
|
+
aioamazondevices/exceptions.py,sha256=CfOFKDvE_yl5BFoFcpTOuDfgRi_2oAtKk-nNJgfWBAs,726
|
5
|
+
aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
aioamazondevices/sounds.py,sha256=01pVCDFIuhrLypXInw4JNuHsC6zjMLsuKocet1R6we8,13409
|
7
|
+
aioamazondevices/utils.py,sha256=RzuKRhnq_8ymCoJMoQJ2vBYyuew06RSWpqQWmqdNczE,2019
|
8
|
+
aioamazondevices-3.2.1.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
|
9
|
+
aioamazondevices-3.2.1.dist-info/METADATA,sha256=qS7EZlIpIOa1F0BMNwW0Z3iAI_g5vFlXv3WSitr7NqI,5234
|
10
|
+
aioamazondevices-3.2.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
11
|
+
aioamazondevices-3.2.1.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
aioamazondevices/__init__.py,sha256=mZIaRiUx4hb3bx5kIhZc9PX7hxD-qnhod-h81ENTXac,277
|
2
|
-
aioamazondevices/api.py,sha256=J4e85fBrHIWPeTvP7TYsezvdHKQ0I_Pqz3HCcdmF6J8,37542
|
3
|
-
aioamazondevices/const.py,sha256=J47aHAfoA6rRgHDvn-q_S4xp8MrC6O1rEk1ZeRnN-8E,8529
|
4
|
-
aioamazondevices/exceptions.py,sha256=JDnSFi_7oEhqK31sHXf0S_cyMoMjiRJuLp4ow7mYgLY,643
|
5
|
-
aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
aioamazondevices/sounds.py,sha256=01pVCDFIuhrLypXInw4JNuHsC6zjMLsuKocet1R6we8,13409
|
7
|
-
aioamazondevices/utils.py,sha256=RzuKRhnq_8ymCoJMoQJ2vBYyuew06RSWpqQWmqdNczE,2019
|
8
|
-
aioamazondevices-3.1.23.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
|
9
|
-
aioamazondevices-3.1.23.dist-info/METADATA,sha256=xEheLDnUfjp1pQbgAMvDsWmOcG5xnDnU8eZfmYSWg4A,5235
|
10
|
-
aioamazondevices-3.1.23.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
11
|
-
aioamazondevices-3.1.23.dist-info/RECORD,,
|
File without changes
|
File without changes
|