aioamazondevices 3.2.9__tar.gz → 3.3.0__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.9
3
+ Version: 3.3.0
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.9"
3
+ version = "3.3.0"
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.9"
3
+ __version__ = "3.3.0"
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 (
@@ -150,6 +150,7 @@ class AmazonEchoApi:
150
150
 
151
151
  self.session: ClientSession
152
152
  self._devices: dict[str, Any] = {}
153
+ self._sensors_available: bool = True
153
154
 
154
155
  if locale and (lang := locale.get("language")):
155
156
  language = lang
@@ -304,29 +305,9 @@ class AmazonEchoApi:
304
305
  """Create HTTP client session."""
305
306
  if not hasattr(self, "session") or self.session.closed:
306
307
  _LOGGER.debug("Creating HTTP session (aiohttp)")
307
- headers = DEFAULT_HEADERS
308
- headers.update({"Accept-Language": self._language})
309
- self.session = ClientSession(
310
- headers=headers,
311
- cookies=self._cookies,
312
- )
313
-
314
- async def _parse_cookies_from_headers(
315
- self, headers: CIMultiDictProxy[str]
316
- ) -> dict[str, str]:
317
- """Parse cookies with a value from headers."""
318
- cookies_with_value: dict[str, str] = {}
319
-
320
- for value in headers.getall("Set-Cookie", ()):
321
- cookie = SimpleCookie()
322
- cookie.load(value)
323
-
324
- for name, morsel in cookie.items():
325
- if morsel.value and morsel.value not in ("-", ""):
326
- cookies_with_value[name] = morsel.value
327
-
328
- _LOGGER.debug("Cookies from headers: %s", cookies_with_value)
329
- return cookies_with_value
308
+ cookie_jar = CookieJar()
309
+ cookie_jar.update_cookies(self._cookies)
310
+ self.session = ClientSession(cookie_jar=cookie_jar)
330
311
 
331
312
  async def _ignore_ap_signin_error(self, response: ClientResponse) -> bool:
332
313
  """Return true if error is due to signin endpoint."""
@@ -381,29 +362,28 @@ class AmazonEchoApi:
381
362
  headers.update({"User-Agent": DEFAULT_AGENT})
382
363
  if self._csrf_cookie:
383
364
  csrf = {CSRF_COOKIE: self._csrf_cookie}
384
- _LOGGER.debug("Adding <%s> to headers", csrf)
365
+ _LOGGER.debug("Adding to headers: %s", csrf)
385
366
  headers.update(csrf)
386
367
 
387
368
  if json_data:
388
369
  json_header = {"Content-Type": "application/json; charset=utf-8"}
389
- _LOGGER.debug("Adding %s to headers", json_header)
370
+ _LOGGER.debug("Adding to headers: %s", json_header)
390
371
  headers.update(json_header)
391
372
 
392
373
  _cookies = (
393
374
  self._load_website_cookies() if self._login_stored_data else self._cookies
394
375
  )
376
+ self.session.cookie_jar.update_cookies(_cookies)
395
377
  try:
396
378
  resp = await self.session.request(
397
379
  method,
398
380
  URL(url, encoded=True),
399
381
  data=input_data if not json_data else orjson.dumps(input_data),
400
- cookies=_cookies,
401
382
  headers=headers,
402
383
  )
403
384
  except (TimeoutError, ClientConnectorError) as exc:
404
385
  raise CannotConnect(f"Connection error during {method}") from exc
405
386
 
406
- self._cookies.update(**await self._parse_cookies_from_headers(resp.headers))
407
387
  if not self._csrf_cookie:
408
388
  self._csrf_cookie = resp.cookies.get(CSRF_COOKIE, Morsel()).value
409
389
  _LOGGER.debug("CSRF cookie value: <%s>", self._csrf_cookie)
@@ -614,6 +594,7 @@ class AmazonEchoApi:
614
594
  URI_IDS,
615
595
  await self._http_phrase_error(raw_resp.status),
616
596
  )
597
+ self._sensors_available = False
617
598
  return []
618
599
 
619
600
  json_data = await raw_resp.json()
@@ -840,10 +821,12 @@ class AmazonEchoApi:
840
821
  else:
841
822
  self._devices[dev_serial] = {key: data}
842
823
 
843
- entity_ids_list = await self._get_devices_ids()
844
- devices_sensors = (
845
- await self._get_sensors_states(entity_ids_list) if entity_ids_list else {}
846
- )
824
+ devices_sensors: dict[str, dict[str, AmazonDeviceSensor]] = {}
825
+
826
+ if self._sensors_available and (
827
+ entity_ids_list := await self._get_devices_ids()
828
+ ):
829
+ devices_sensors = await self._get_sensors_states(entity_ids_list)
847
830
 
848
831
  final_devices_list: dict[str, AmazonDevice] = {}
849
832
  for device in self._devices.values():