aioamazondevices 3.2.10__tar.gz → 3.3.1__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: 3.2.10
3
+ Version: 3.3.1
4
4
  Summary: Python library to control Amazon devices
5
5
  License: Apache-2.0
6
6
  Author: Simone Chemelli
@@ -11,7 +11,7 @@ Classifier: Intended Audience :: Developers
11
11
  Classifier: Natural Language :: English
12
12
  Classifier: Operating System :: OS Independent
13
13
  Classifier: Topic :: Software Development :: Libraries
14
- Requires-Dist: aiohttp
14
+ Requires-Dist: aiohttp (>=3.12.7)
15
15
  Requires-Dist: beautifulsoup4
16
16
  Requires-Dist: colorlog
17
17
  Requires-Dist: langcodes
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "aioamazondevices"
3
- version = "3.2.10"
3
+ version = "3.3.1"
4
4
  requires-python = ">=3.12"
5
5
  description = "Python library to control Amazon devices"
6
6
  authors = [
@@ -20,7 +20,7 @@ packages = [
20
20
  { include = "aioamazondevices", from = "src" },
21
21
  ]
22
22
  dependencies = [
23
- "aiohttp",
23
+ "aiohttp (>=3.12.7)",
24
24
  "beautifulsoup4",
25
25
  "colorlog",
26
26
  "langcodes",
@@ -1,6 +1,6 @@
1
1
  """aioamazondevices library."""
2
2
 
3
- __version__ = "3.2.10"
3
+ __version__ = "3.3.1"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
@@ -9,16 +9,16 @@ from dataclasses import dataclass
9
9
  from datetime import UTC, datetime, timedelta
10
10
  from enum import StrEnum
11
11
  from http import HTTPMethod, HTTPStatus
12
- from http.cookies import Morsel, SimpleCookie
12
+ from http.cookies import Morsel
13
13
  from pathlib import Path
14
14
  from typing import Any, cast
15
15
  from urllib.parse import parse_qs, urlencode
16
16
 
17
17
  import orjson
18
- from aiohttp import ClientConnectorError, ClientResponse, ClientSession
18
+ from aiohttp import ClientConnectorError, ClientResponse, ClientSession, CookieJar
19
19
  from bs4 import BeautifulSoup, Tag
20
20
  from langcodes import Language
21
- from multidict import CIMultiDictProxy, MultiDictProxy
21
+ from multidict import MultiDictProxy
22
22
  from yarl import URL
23
23
 
24
24
  from .const import (
@@ -305,29 +305,9 @@ class AmazonEchoApi:
305
305
  """Create HTTP client session."""
306
306
  if not hasattr(self, "session") or self.session.closed:
307
307
  _LOGGER.debug("Creating HTTP session (aiohttp)")
308
- headers = DEFAULT_HEADERS
309
- headers.update({"Accept-Language": self._language})
310
- self.session = ClientSession(
311
- headers=headers,
312
- cookies=self._cookies,
313
- )
314
-
315
- async def _parse_cookies_from_headers(
316
- self, headers: CIMultiDictProxy[str]
317
- ) -> dict[str, str]:
318
- """Parse cookies with a value from headers."""
319
- cookies_with_value: dict[str, str] = {}
320
-
321
- for value in headers.getall("Set-Cookie", ()):
322
- cookie = SimpleCookie()
323
- cookie.load(value)
324
-
325
- for name, morsel in cookie.items():
326
- if morsel.value and morsel.value not in ("-", ""):
327
- cookies_with_value[name] = morsel.value
328
-
329
- _LOGGER.debug("Cookies from headers: %s", cookies_with_value)
330
- return cookies_with_value
308
+ cookie_jar = CookieJar()
309
+ cookie_jar.update_cookies(self._cookies)
310
+ self.session = ClientSession(cookie_jar=cookie_jar)
331
311
 
332
312
  async def _ignore_ap_signin_error(self, response: ClientResponse) -> bool:
333
313
  """Return true if error is due to signin endpoint."""
@@ -382,29 +362,28 @@ class AmazonEchoApi:
382
362
  headers.update({"User-Agent": DEFAULT_AGENT})
383
363
  if self._csrf_cookie:
384
364
  csrf = {CSRF_COOKIE: self._csrf_cookie}
385
- _LOGGER.debug("Adding <%s> to headers", csrf)
365
+ _LOGGER.debug("Adding to headers: %s", csrf)
386
366
  headers.update(csrf)
387
367
 
388
368
  if json_data:
389
369
  json_header = {"Content-Type": "application/json; charset=utf-8"}
390
- _LOGGER.debug("Adding %s to headers", json_header)
370
+ _LOGGER.debug("Adding to headers: %s", json_header)
391
371
  headers.update(json_header)
392
372
 
393
373
  _cookies = (
394
374
  self._load_website_cookies() if self._login_stored_data else self._cookies
395
375
  )
376
+ self.session.cookie_jar.update_cookies(_cookies)
396
377
  try:
397
378
  resp = await self.session.request(
398
379
  method,
399
380
  URL(url, encoded=True),
400
381
  data=input_data if not json_data else orjson.dumps(input_data),
401
- cookies=_cookies,
402
382
  headers=headers,
403
383
  )
404
384
  except (TimeoutError, ClientConnectorError) as exc:
405
385
  raise CannotConnect(f"Connection error during {method}") from exc
406
386
 
407
- self._cookies.update(**await self._parse_cookies_from_headers(resp.headers))
408
387
  if not self._csrf_cookie:
409
388
  self._csrf_cookie = resp.cookies.get(CSRF_COOKIE, Morsel()).value
410
389
  _LOGGER.debug("CSRF cookie value: <%s>", self._csrf_cookie)
@@ -42,7 +42,7 @@ DOMAIN_BY_ISO3166_COUNTRY = {
42
42
  },
43
43
  "au": {
44
44
  "domain": "com.au",
45
- "openid.assoc_handle": DEFAULT_ASSOC_HANDLE,
45
+ "openid.assoc_handle": f"{DEFAULT_ASSOC_HANDLE}_au",
46
46
  },
47
47
  "be": {
48
48
  "domain": "com.be",
@@ -66,7 +66,7 @@ DOMAIN_BY_ISO3166_COUNTRY = {
66
66
  },
67
67
  "nz": {
68
68
  "domain": "com.au",
69
- "openid.assoc_handle": DEFAULT_ASSOC_HANDLE,
69
+ "openid.assoc_handle": f"{DEFAULT_ASSOC_HANDLE}_au",
70
70
  },
71
71
  "tr": {
72
72
  "domain": "com.tr",