aioamazondevices 3.7.0__py3-none-any.whl → 4.0.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 +18 -30
- aioamazondevices/const.py +5 -3
- {aioamazondevices-3.7.0.dist-info → aioamazondevices-4.0.1.dist-info}/METADATA +14 -7
- aioamazondevices-4.0.1.dist-info/RECORD +11 -0
- aioamazondevices-3.7.0.dist-info/RECORD +0 -11
- {aioamazondevices-3.7.0.dist-info → aioamazondevices-4.0.1.dist-info}/LICENSE +0 -0
- {aioamazondevices-3.7.0.dist-info → aioamazondevices-4.0.1.dist-info}/WHEEL +0 -0
aioamazondevices/__init__.py
CHANGED
aioamazondevices/api.py
CHANGED
@@ -16,7 +16,7 @@ from typing import Any, cast
|
|
16
16
|
from urllib.parse import parse_qs, urlencode
|
17
17
|
|
18
18
|
import orjson
|
19
|
-
from aiohttp import ClientConnectorError, ClientResponse, ClientSession
|
19
|
+
from aiohttp import ClientConnectorError, ClientResponse, ClientSession
|
20
20
|
from bs4 import BeautifulSoup, Tag
|
21
21
|
from langcodes import Language
|
22
22
|
from multidict import MultiDictProxy
|
@@ -121,20 +121,20 @@ class AmazonEchoApi:
|
|
121
121
|
|
122
122
|
def __init__(
|
123
123
|
self,
|
124
|
+
client_session: ClientSession,
|
124
125
|
login_country_code: str,
|
125
126
|
login_email: str,
|
126
127
|
login_password: str,
|
127
128
|
login_data: dict[str, Any] | None = None,
|
128
|
-
save_raw_data: bool = False,
|
129
129
|
) -> None:
|
130
130
|
"""Initialize the scanner."""
|
131
131
|
# Force country digits as lower case
|
132
132
|
country_code = login_country_code.lower()
|
133
133
|
|
134
|
-
locale = DOMAIN_BY_ISO3166_COUNTRY.get(country_code, {})
|
135
|
-
domain = locale.get("domain", country_code)
|
136
|
-
market = locale.get("market", f"https://www.amazon.{domain}")
|
137
|
-
assoc_handle = locale.get(
|
134
|
+
locale: dict = DOMAIN_BY_ISO3166_COUNTRY.get(country_code, {})
|
135
|
+
domain: str = locale.get("domain", country_code)
|
136
|
+
market: list[str] = locale.get("market", [f"https://www.amazon.{domain}"])
|
137
|
+
assoc_handle: str = locale.get(
|
138
138
|
"openid.assoc_handle", f"{DEFAULT_ASSOC_HANDLE}_{country_code}"
|
139
139
|
)
|
140
140
|
|
@@ -146,12 +146,12 @@ class AmazonEchoApi:
|
|
146
146
|
self._market = market
|
147
147
|
self._cookies = self._build_init_cookies()
|
148
148
|
self._csrf_cookie: str | None = None
|
149
|
-
self._save_raw_data =
|
149
|
+
self._save_raw_data = False
|
150
150
|
self._login_stored_data = login_data
|
151
151
|
self._serial = self._serial_number()
|
152
152
|
self._list_for_clusters: dict[str, str] = {}
|
153
153
|
|
154
|
-
self.
|
154
|
+
self._session = client_session
|
155
155
|
self._devices: dict[str, Any] = {}
|
156
156
|
self._sensors_available: bool = True
|
157
157
|
|
@@ -167,6 +167,11 @@ class AmazonEchoApi:
|
|
167
167
|
self._market,
|
168
168
|
)
|
169
169
|
|
170
|
+
def save_raw_data(self) -> None:
|
171
|
+
"""Save raw data to disk."""
|
172
|
+
self._save_raw_data = True
|
173
|
+
_LOGGER.debug("Saving raw data to disk")
|
174
|
+
|
170
175
|
def _load_website_cookies(self) -> dict[str, str]:
|
171
176
|
"""Get website cookies, if avaliables."""
|
172
177
|
if not self._login_stored_data:
|
@@ -301,14 +306,6 @@ class AmazonEchoApi:
|
|
301
306
|
raise TypeError(f"Unable to extract authorization code from url: {url}")
|
302
307
|
return parsed_url["openid.oa2.authorization_code"][0]
|
303
308
|
|
304
|
-
def _client_session(self) -> None:
|
305
|
-
"""Create HTTP client session."""
|
306
|
-
if not hasattr(self, "session") or self.session.closed:
|
307
|
-
_LOGGER.debug("Creating HTTP session (aiohttp)")
|
308
|
-
cookie_jar = CookieJar()
|
309
|
-
cookie_jar.update_cookies(self._cookies)
|
310
|
-
self.session = ClientSession(cookie_jar=cookie_jar)
|
311
|
-
|
312
309
|
async def _ignore_ap_signin_error(self, response: ClientResponse) -> bool:
|
313
310
|
"""Return true if error is due to signin endpoint."""
|
314
311
|
# Endpoint URI_SIGNIN replies with error 404
|
@@ -373,7 +370,7 @@ class AmazonEchoApi:
|
|
373
370
|
_cookies = (
|
374
371
|
self._load_website_cookies() if self._login_stored_data else self._cookies
|
375
372
|
)
|
376
|
-
self.
|
373
|
+
self._session.cookie_jar.update_cookies(_cookies)
|
377
374
|
|
378
375
|
resp: ClientResponse | None = None
|
379
376
|
for delay in [0, 1, 2, 5, 8, 12, 21]:
|
@@ -384,7 +381,7 @@ class AmazonEchoApi:
|
|
384
381
|
await asyncio.sleep(delay)
|
385
382
|
|
386
383
|
try:
|
387
|
-
resp = await self.
|
384
|
+
resp = await self._session.request(
|
388
385
|
method,
|
389
386
|
URL(url, encoded=True),
|
390
387
|
data=input_data if not json_data else orjson.dumps(input_data),
|
@@ -590,9 +587,9 @@ class AmazonEchoApi:
|
|
590
587
|
resp_me_json = await resp_me.json()
|
591
588
|
amazon_market = resp_me_json["marketPlaceDomainName"]
|
592
589
|
|
593
|
-
if amazon_market
|
590
|
+
if amazon_market not in self._market:
|
594
591
|
_LOGGER.warning(
|
595
|
-
"Selected country <%s> doesn't
|
592
|
+
"Selected country <%s> doesn't match Amazon API reply:\n%s\n vs \n%s",
|
596
593
|
self._login_country_code.upper(),
|
597
594
|
{"input ": self._market},
|
598
595
|
{"amazon": amazon_market},
|
@@ -730,7 +727,6 @@ class AmazonEchoApi:
|
|
730
727
|
obfuscate_email(self._login_email),
|
731
728
|
bool(otp_code),
|
732
729
|
)
|
733
|
-
self._client_session()
|
734
730
|
|
735
731
|
code_verifier = self._create_code_verifier()
|
736
732
|
client_id = self._build_client_id()
|
@@ -805,18 +801,10 @@ class AmazonEchoApi:
|
|
805
801
|
obfuscate_email(self._login_email),
|
806
802
|
)
|
807
803
|
|
808
|
-
self._client_session()
|
809
|
-
|
810
804
|
await self._check_country()
|
811
805
|
|
812
806
|
return self._login_stored_data
|
813
807
|
|
814
|
-
async def close(self) -> None:
|
815
|
-
"""Close http client session."""
|
816
|
-
if hasattr(self, "session"):
|
817
|
-
_LOGGER.debug("Closing HTTP session (aiohttp)")
|
818
|
-
await self.session.close()
|
819
|
-
|
820
808
|
async def get_devices_data(
|
821
809
|
self,
|
822
810
|
) -> dict[str, AmazonDevice]:
|
@@ -945,7 +933,7 @@ class AmazonEchoApi:
|
|
945
933
|
) -> None:
|
946
934
|
"""Send message to specific device."""
|
947
935
|
if not self._login_stored_data:
|
948
|
-
_LOGGER.warning("
|
936
|
+
_LOGGER.warning("No login data available, cannot send message")
|
949
937
|
return
|
950
938
|
|
951
939
|
base_payload = {
|
aioamazondevices/const.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"""Constants for Amazon devices."""
|
2
2
|
|
3
3
|
import logging
|
4
|
+
from typing import Any
|
4
5
|
|
5
6
|
_LOGGER = logging.getLogger(__package__)
|
6
7
|
|
@@ -30,16 +31,16 @@ TO_REDACT = {
|
|
30
31
|
"user_id",
|
31
32
|
}
|
32
33
|
|
33
|
-
AMAZON_DE_OVERRIDE = {
|
34
|
+
AMAZON_DE_OVERRIDE: dict[str, str] = {
|
34
35
|
"domain": "de",
|
35
36
|
"openid.assoc_handle": f"{DEFAULT_ASSOC_HANDLE}_de",
|
36
37
|
}
|
37
|
-
AMAZON_US_OVERRIDE = {
|
38
|
+
AMAZON_US_OVERRIDE: dict[str, str] = {
|
38
39
|
"domain": "com",
|
39
40
|
"openid.assoc_handle": DEFAULT_ASSOC_HANDLE,
|
40
41
|
}
|
41
42
|
|
42
|
-
DOMAIN_BY_ISO3166_COUNTRY = {
|
43
|
+
DOMAIN_BY_ISO3166_COUNTRY: dict[str, dict[str, Any]] = {
|
43
44
|
"ar": AMAZON_US_OVERRIDE,
|
44
45
|
"at": AMAZON_DE_OVERRIDE,
|
45
46
|
"au": {
|
@@ -70,6 +71,7 @@ DOMAIN_BY_ISO3166_COUNTRY = {
|
|
70
71
|
"domain": "com.au",
|
71
72
|
"openid.assoc_handle": f"{DEFAULT_ASSOC_HANDLE}_au",
|
72
73
|
},
|
74
|
+
"pl": AMAZON_US_OVERRIDE,
|
73
75
|
"tr": {
|
74
76
|
"domain": "com.tr",
|
75
77
|
},
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: aioamazondevices
|
3
|
-
Version:
|
3
|
+
Version: 4.0.1
|
4
4
|
Summary: Python library to control Amazon devices
|
5
5
|
License: Apache-2.0
|
6
6
|
Author: Simone Chemelli
|
@@ -114,17 +114,17 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
114
114
|
</a>
|
115
115
|
</td>
|
116
116
|
<td align="center">
|
117
|
-
<a href="https://github.com/
|
118
|
-
<img src="https://avatars.githubusercontent.com/u/
|
117
|
+
<a href="https://github.com/jamesonuk">
|
118
|
+
<img src="https://avatars.githubusercontent.com/u/1040621?v=4" width="100;" alt="jamesonuk"/>
|
119
119
|
<br />
|
120
|
-
<sub><b>
|
120
|
+
<sub><b>jameson_uk</b></sub>
|
121
121
|
</a>
|
122
122
|
</td>
|
123
123
|
<td align="center">
|
124
|
-
<a href="https://github.com/
|
125
|
-
<img src="https://avatars.githubusercontent.com/u/
|
124
|
+
<a href="https://github.com/jeeftor">
|
125
|
+
<img src="https://avatars.githubusercontent.com/u/6491743?v=4" width="100;" alt="jeeftor"/>
|
126
126
|
<br />
|
127
|
-
<sub><b>
|
127
|
+
<sub><b>Jeef</b></sub>
|
128
128
|
</a>
|
129
129
|
</td>
|
130
130
|
<td align="center">
|
@@ -150,6 +150,13 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
150
150
|
</td>
|
151
151
|
</tr>
|
152
152
|
<tr>
|
153
|
+
<td align="center">
|
154
|
+
<a href="https://github.com/maxmati">
|
155
|
+
<img src="https://avatars.githubusercontent.com/u/509560?v=4" width="100;" alt="maxmati"/>
|
156
|
+
<br />
|
157
|
+
<sub><b>Mateusz Nowotyński</b></sub>
|
158
|
+
</a>
|
159
|
+
</td>
|
153
160
|
<td align="center">
|
154
161
|
<a href="https://github.com/tronikos">
|
155
162
|
<img src="https://avatars.githubusercontent.com/u/9987465?v=4" width="100;" alt="tronikos"/>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
aioamazondevices/__init__.py,sha256=B40dT-9Wsok6OrOhyn7tENG8RwetooNRONmpiNZ_4U0,276
|
2
|
+
aioamazondevices/api.py,sha256=HIgewk7CuYpNeflPjX0EarKMYmrMuOP0weKUJD1oY2Q,41075
|
3
|
+
aioamazondevices/const.py,sha256=T4OSoLFhHA16n-5wKyzMAIYZUDmoowLSEjVLx8C3PE0,11498
|
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-4.0.1.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
|
9
|
+
aioamazondevices-4.0.1.dist-info/METADATA,sha256=nmKoeiuQyst5FNR2Tu7Do9Wjr7vxc_waxf4z8BSudQI,7572
|
10
|
+
aioamazondevices-4.0.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
11
|
+
aioamazondevices-4.0.1.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
aioamazondevices/__init__.py,sha256=znb9LZwJ1BoJyNPfIw2LN6xoILglQMI3yxmCWh_wOTk,276
|
2
|
-
aioamazondevices/api.py,sha256=Z65R_DSUQnHci0_gs1PB4dwm2K_bqaaYBbPBc6GfLcU,41525
|
3
|
-
aioamazondevices/const.py,sha256=1v0CFgGrf99tnfxKED7B-uvbT7rpiVJzFV6cjFmEoOM,11386
|
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.7.0.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
|
9
|
-
aioamazondevices-3.7.0.dist-info/METADATA,sha256=vxgP2t5VhcXPzBbWnWbuR3s2S9LECICjzredGb7a9eI,7251
|
10
|
-
aioamazondevices-3.7.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
11
|
-
aioamazondevices-3.7.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|