aioamazondevices 6.5.2__tar.gz → 6.5.3__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.4
2
2
  Name: aioamazondevices
3
- Version: 6.5.2
3
+ Version: 6.5.3
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.5.2"
3
+ version = "6.5.3"
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.5.2"
3
+ __version__ = "6.5.3"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
@@ -630,8 +630,7 @@ class AmazonEchoApi:
630
630
  json_data=True,
631
631
  )
632
632
 
633
- sensors_state = await self._response_to_json(raw_resp)
634
- _LOGGER.debug("Sensor data - %s", sensors_state)
633
+ sensors_state = await self._response_to_json(raw_resp, "sensors")
635
634
 
636
635
  if await self._format_human_error(sensors_state):
637
636
  # Explicit error in returned data
@@ -740,7 +739,7 @@ class AmazonEchoApi:
740
739
  json_data=True,
741
740
  )
742
741
 
743
- endpoint_data = await self._response_to_json(raw_resp)
742
+ endpoint_data = await self._response_to_json(raw_resp, "endpoint")
744
743
 
745
744
  if not (data := endpoint_data.get("data")) or not data.get("listEndpoints"):
746
745
  await self._format_human_error(endpoint_data)
@@ -760,7 +759,9 @@ class AmazonEchoApi:
760
759
 
761
760
  return devices_endpoints
762
761
 
763
- async def _response_to_json(self, raw_resp: ClientResponse) -> dict[str, Any]:
762
+ async def _response_to_json(
763
+ self, raw_resp: ClientResponse, description: str | None = None
764
+ ) -> dict[str, Any]:
764
765
  """Convert response to JSON, if possible."""
765
766
  try:
766
767
  data = await raw_resp.json(loads=orjson.loads)
@@ -771,6 +772,8 @@ class AmazonEchoApi:
771
772
  # if anonymous array is returned wrap it inside
772
773
  # generated key to convert list to dict
773
774
  data = {ARRAY_WRAPPER: data}
775
+ if description:
776
+ _LOGGER.debug("JSON '%s' data: %s", description, scrub_fields(data))
774
777
  return cast("dict[str, Any]", data)
775
778
  except ContentTypeError as exc:
776
779
  raise ValueError("Response not in JSON format") from exc
@@ -784,7 +787,9 @@ class AmazonEchoApi:
784
787
  HTTPMethod.GET,
785
788
  url=f"https://alexa.amazon.{self._domain}{URI_NOTIFICATIONS}",
786
789
  )
787
- notifications = await self._response_to_json(raw_resp)
790
+
791
+ notifications = await self._response_to_json(raw_resp, "notifications")
792
+
788
793
  for schedule in notifications["notifications"]:
789
794
  schedule_type: str = schedule["type"]
790
795
  schedule_device_serial = schedule["deviceSerialNumber"]
@@ -869,7 +874,11 @@ class AmazonEchoApi:
869
874
  continue
870
875
 
871
876
  if recurring_rule not in RECURRING_PATTERNS:
872
- _LOGGER.warning("Unknown recurring rule: %s", recurring_rule)
877
+ _LOGGER.warning(
878
+ "Unknown recurring rule <%s> for schedule type <%s>",
879
+ recurring_rule,
880
+ schedule["type"],
881
+ )
873
882
  return None
874
883
 
875
884
  # Adjust recurring rules for country specific weekend exceptions
@@ -1147,6 +1156,9 @@ class AmazonEchoApi:
1147
1156
  ) and device.device_family != SPEAKER_GROUP_FAMILY:
1148
1157
  device.sensors["dnd"] = device_dnd
1149
1158
 
1159
+ # Clear old notifications to handle cancelled ones
1160
+ device.notifications = {}
1161
+
1150
1162
  # Update notifications
1151
1163
  device_notifications = notifications.get(device.serial_number, {})
1152
1164
 
@@ -1188,9 +1200,7 @@ class AmazonEchoApi:
1188
1200
  url=f"https://alexa.amazon.{self._domain}{URI_DEVICES}",
1189
1201
  )
1190
1202
 
1191
- json_data = await self._response_to_json(raw_resp)
1192
-
1193
- _LOGGER.debug("JSON devices data: %s", scrub_fields(json_data))
1203
+ json_data = await self._response_to_json(raw_resp, "devices")
1194
1204
 
1195
1205
  for data in json_data["devices"]:
1196
1206
  dev_serial = data.get("serialNumber")
@@ -1538,8 +1548,7 @@ class AmazonEchoApi:
1538
1548
  _LOGGER.debug("Failed to refresh data")
1539
1549
  return False, {}
1540
1550
 
1541
- json_response = await self._response_to_json(raw_resp)
1542
- _LOGGER.debug("Refresh data json:\n%s ", json_response)
1551
+ json_response = await self._response_to_json(raw_resp, data_type)
1543
1552
 
1544
1553
  if data_type == REFRESH_ACCESS_TOKEN and (
1545
1554
  new_token := json_response.get(REFRESH_ACCESS_TOKEN)
@@ -1563,8 +1572,7 @@ class AmazonEchoApi:
1563
1572
  url=f"https://alexa.amazon.{self._domain}{URI_DND}",
1564
1573
  )
1565
1574
 
1566
- dnd_data = await self._response_to_json(raw_resp)
1567
- _LOGGER.debug("DND data: %s", dnd_data)
1575
+ dnd_data = await self._response_to_json(raw_resp, "dnd")
1568
1576
 
1569
1577
  for dnd in dnd_data.get("doNotDisturbDeviceStatusList", {}):
1570
1578
  dnd_status[dnd.get("deviceSerialNumber")] = AmazonDeviceSensor(