aioamazondevices 6.4.4__tar.gz → 6.4.6__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.

Potentially problematic release.


This version of aioamazondevices might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aioamazondevices
3
- Version: 6.4.4
3
+ Version: 6.4.6
4
4
  Summary: Python library to control Amazon devices
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "aioamazondevices"
3
- version = "6.4.4"
3
+ version = "6.4.6"
4
4
  requires-python = ">=3.12"
5
5
  description = "Python library to control Amazon devices"
6
6
  authors = [
@@ -1,6 +1,6 @@
1
1
  """aioamazondevices library."""
2
2
 
3
- __version__ = "6.4.4"
3
+ __version__ = "6.4.6"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
@@ -50,6 +50,7 @@ from .const import (
50
50
  JSON_EXTENSION,
51
51
  REFRESH_ACCESS_TOKEN,
52
52
  REFRESH_AUTH_COOKIES,
53
+ REQUEST_AGENT,
53
54
  SAVE_PATH,
54
55
  SENSORS,
55
56
  URI_DEVICES,
@@ -347,6 +348,7 @@ class AmazonEchoApi:
347
348
  url: str,
348
349
  input_data: dict[str, Any] | list[dict[str, Any]] | None = None,
349
350
  json_data: bool = False,
351
+ agent: str = "Amazon",
350
352
  ) -> tuple[BeautifulSoup, ClientResponse]:
351
353
  """Return request response context data."""
352
354
  _LOGGER.debug(
@@ -358,6 +360,7 @@ class AmazonEchoApi:
358
360
  )
359
361
 
360
362
  headers = DEFAULT_HEADERS.copy()
363
+ headers.update({"User-Agent": REQUEST_AGENT[agent]})
361
364
  headers.update({"Accept-Language": self._language})
362
365
 
363
366
  if self._csrf_cookie:
@@ -940,8 +943,13 @@ class AmazonEchoApi:
940
943
  await self._get_base_devices()
941
944
  self._last_devices_refresh = datetime.now(UTC)
942
945
 
946
+ # Only refresh endpoint data if we have no endpoints yet
943
947
  delta_endpoints = datetime.now(UTC) - self._last_endpoint_refresh
944
- if delta_endpoints >= timedelta(minutes=30):
948
+ endpoint_refresh_needed = delta_endpoints >= timedelta(days=1)
949
+ endpoints_recently_checked = delta_endpoints < timedelta(minutes=30)
950
+ if (
951
+ not self._endpoints and not endpoints_recently_checked
952
+ ) or endpoint_refresh_needed:
945
953
  _LOGGER.debug(
946
954
  "Refreshing endpoint data after %s",
947
955
  str(timedelta(minutes=round(delta_endpoints.total_seconds() / 60))),
@@ -969,6 +977,7 @@ class AmazonEchoApi:
969
977
  device.sensors["dnd"] = device_dnd
970
978
 
971
979
  async def _set_device_endpoints_data(self) -> None:
980
+ """Set device endpoint data."""
972
981
  devices_endpoints = await self._get_devices_endpoint_data()
973
982
  for serial_number in self._final_devices:
974
983
  device_endpoint = devices_endpoints.get(serial_number, {})
@@ -1046,6 +1055,7 @@ class AmazonEchoApi:
1046
1055
  _, raw_resp = await self._session_request(
1047
1056
  method=HTTPMethod.GET,
1048
1057
  url=f"https://alexa.amazon.{self._domain}/api/bootstrap?version=0",
1058
+ agent="Browser",
1049
1059
  )
1050
1060
  if raw_resp.status != HTTPStatus.OK:
1051
1061
  _LOGGER.debug(
@@ -1253,7 +1263,7 @@ class AmazonEchoApi:
1253
1263
  device: AmazonDevice,
1254
1264
  message_body: str,
1255
1265
  ) -> None:
1256
- """Call Alexa.Sound to play sound."""
1266
+ """Call Alexa.TextCommand to issue command."""
1257
1267
  return await self._send_message(
1258
1268
  device, AmazonSequenceType.TextCommand, message_body
1259
1269
  )
@@ -39,14 +39,15 @@ AMAZON_CLIENT_OS = "18.5"
39
39
 
40
40
  DEFAULT_SITE = "https://www.amazon.com"
41
41
  DEFAULT_HEADERS = {
42
- "User-Agent": (
43
- f"AmazonWebView/AmazonAlexa/{AMAZON_APP_VERSION}/iOS/{AMAZON_CLIENT_OS}/iPhone"
44
- ),
45
42
  "Accept-Charset": "utf-8",
46
43
  "Accept-Encoding": "gzip",
47
44
  "Connection": "keep-alive",
48
45
  }
49
46
  CSRF_COOKIE = "csrf"
47
+ REQUEST_AGENT = {
48
+ "Amazon": f"AmazonWebView/AmazonAlexa/{AMAZON_APP_VERSION}/iOS/{AMAZON_CLIENT_OS}/iPhone", # noqa: E501
49
+ "Browser": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0", # noqa: E501
50
+ }
50
51
 
51
52
  REFRESH_ACCESS_TOKEN = "access_token" # noqa: S105
52
53
  REFRESH_AUTH_COOKIES = "auth_cookies"
@@ -184,7 +185,7 @@ DEVICE_TYPE_TO_MODEL: dict[str, dict[str, str | None]] = {
184
185
  "model": "Echo Dot",
185
186
  "hw_version": "Gen3",
186
187
  },
187
- "A1TD5Z1R8IWBHA ": {
188
+ "A1TD5Z1R8IWBHA": {
188
189
  "model": "Fire Tablet HD 8",
189
190
  "hw_version": "Gen12",
190
191
  },
@@ -235,7 +236,7 @@ DEVICE_TYPE_TO_MODEL: dict[str, dict[str, str | None]] = {
235
236
  "model": "Echo Dot Clock",
236
237
  "hw_version": "Gen5",
237
238
  },
238
- "A2E0SNTXJVT7WK ": {
239
+ "A2E0SNTXJVT7WK": {
239
240
  "model": "Fire TV Stick",
240
241
  "hw_version": "Gen2",
241
242
  },
@@ -319,7 +320,7 @@ DEVICE_TYPE_TO_MODEL: dict[str, dict[str, str | None]] = {
319
320
  "model": "Echo Dot",
320
321
  "hw_version": "Gen3",
321
322
  },
322
- "A33S43L213VSHQ ": {
323
+ "A33S43L213VSHQ": {
323
324
  "model": "Smart TV 4K",
324
325
  "hw_version": "4 Series",
325
326
  },