aioamazondevices 6.5.2__tar.gz → 6.5.4__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.4
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.4"
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.4"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
@@ -56,6 +56,7 @@ from .const import (
56
56
  NOTIFICATION_MUSIC_ALARM,
57
57
  NOTIFICATION_REMINDER,
58
58
  NOTIFICATION_TIMER,
59
+ NOTIFICATIONS_SUPPORTED,
59
60
  RECURRING_PATTERNS,
60
61
  REFRESH_ACCESS_TOKEN,
61
62
  REFRESH_AUTH_COOKIES,
@@ -630,8 +631,7 @@ class AmazonEchoApi:
630
631
  json_data=True,
631
632
  )
632
633
 
633
- sensors_state = await self._response_to_json(raw_resp)
634
- _LOGGER.debug("Sensor data - %s", sensors_state)
634
+ sensors_state = await self._response_to_json(raw_resp, "sensors")
635
635
 
636
636
  if await self._format_human_error(sensors_state):
637
637
  # Explicit error in returned data
@@ -740,7 +740,7 @@ class AmazonEchoApi:
740
740
  json_data=True,
741
741
  )
742
742
 
743
- endpoint_data = await self._response_to_json(raw_resp)
743
+ endpoint_data = await self._response_to_json(raw_resp, "endpoint")
744
744
 
745
745
  if not (data := endpoint_data.get("data")) or not data.get("listEndpoints"):
746
746
  await self._format_human_error(endpoint_data)
@@ -760,7 +760,9 @@ class AmazonEchoApi:
760
760
 
761
761
  return devices_endpoints
762
762
 
763
- async def _response_to_json(self, raw_resp: ClientResponse) -> dict[str, Any]:
763
+ async def _response_to_json(
764
+ self, raw_resp: ClientResponse, description: str | None = None
765
+ ) -> dict[str, Any]:
764
766
  """Convert response to JSON, if possible."""
765
767
  try:
766
768
  data = await raw_resp.json(loads=orjson.loads)
@@ -771,6 +773,8 @@ class AmazonEchoApi:
771
773
  # if anonymous array is returned wrap it inside
772
774
  # generated key to convert list to dict
773
775
  data = {ARRAY_WRAPPER: data}
776
+ if description:
777
+ _LOGGER.debug("JSON '%s' data: %s", description, scrub_fields(data))
774
778
  return cast("dict[str, Any]", data)
775
779
  except ContentTypeError as exc:
776
780
  raise ValueError("Response not in JSON format") from exc
@@ -784,10 +788,24 @@ class AmazonEchoApi:
784
788
  HTTPMethod.GET,
785
789
  url=f"https://alexa.amazon.{self._domain}{URI_NOTIFICATIONS}",
786
790
  )
787
- notifications = await self._response_to_json(raw_resp)
791
+
792
+ notifications = await self._response_to_json(raw_resp, "notifications")
793
+
788
794
  for schedule in notifications["notifications"]:
789
795
  schedule_type: str = schedule["type"]
790
796
  schedule_device_serial = schedule["deviceSerialNumber"]
797
+
798
+ if schedule_device_serial in DEVICE_TO_IGNORE:
799
+ continue
800
+
801
+ if schedule_type not in NOTIFICATIONS_SUPPORTED:
802
+ _LOGGER.debug(
803
+ "Unsupported schedule type %s for device %s",
804
+ schedule_type,
805
+ schedule_device_serial,
806
+ )
807
+ continue
808
+
791
809
  if schedule_type == NOTIFICATION_MUSIC_ALARM:
792
810
  # Structure is the same as standard Alarm
793
811
  schedule_type = NOTIFICATION_ALARM
@@ -869,7 +887,11 @@ class AmazonEchoApi:
869
887
  continue
870
888
 
871
889
  if recurring_rule not in RECURRING_PATTERNS:
872
- _LOGGER.warning("Unknown recurring rule: %s", recurring_rule)
890
+ _LOGGER.warning(
891
+ "Unknown recurring rule <%s> for schedule type <%s>",
892
+ recurring_rule,
893
+ schedule["type"],
894
+ )
873
895
  return None
874
896
 
875
897
  # Adjust recurring rules for country specific weekend exceptions
@@ -1147,6 +1169,9 @@ class AmazonEchoApi:
1147
1169
  ) and device.device_family != SPEAKER_GROUP_FAMILY:
1148
1170
  device.sensors["dnd"] = device_dnd
1149
1171
 
1172
+ # Clear old notifications to handle cancelled ones
1173
+ device.notifications = {}
1174
+
1150
1175
  # Update notifications
1151
1176
  device_notifications = notifications.get(device.serial_number, {})
1152
1177
 
@@ -1188,9 +1213,7 @@ class AmazonEchoApi:
1188
1213
  url=f"https://alexa.amazon.{self._domain}{URI_DEVICES}",
1189
1214
  )
1190
1215
 
1191
- json_data = await self._response_to_json(raw_resp)
1192
-
1193
- _LOGGER.debug("JSON devices data: %s", scrub_fields(json_data))
1216
+ json_data = await self._response_to_json(raw_resp, "devices")
1194
1217
 
1195
1218
  for data in json_data["devices"]:
1196
1219
  dev_serial = data.get("serialNumber")
@@ -1538,8 +1561,7 @@ class AmazonEchoApi:
1538
1561
  _LOGGER.debug("Failed to refresh data")
1539
1562
  return False, {}
1540
1563
 
1541
- json_response = await self._response_to_json(raw_resp)
1542
- _LOGGER.debug("Refresh data json:\n%s ", json_response)
1564
+ json_response = await self._response_to_json(raw_resp, data_type)
1543
1565
 
1544
1566
  if data_type == REFRESH_ACCESS_TOKEN and (
1545
1567
  new_token := json_response.get(REFRESH_ACCESS_TOKEN)
@@ -1563,8 +1585,7 @@ class AmazonEchoApi:
1563
1585
  url=f"https://alexa.amazon.{self._domain}{URI_DND}",
1564
1586
  )
1565
1587
 
1566
- dnd_data = await self._response_to_json(raw_resp)
1567
- _LOGGER.debug("DND data: %s", dnd_data)
1588
+ dnd_data = await self._response_to_json(raw_resp, "dnd")
1568
1589
 
1569
1590
  for dnd in dnd_data.get("doNotDisturbDeviceStatusList", {}):
1570
1591
  dnd_status[dnd.get("deviceSerialNumber")] = AmazonDeviceSensor(
@@ -534,3 +534,9 @@ NOTIFICATION_ALARM = "Alarm"
534
534
  NOTIFICATION_MUSIC_ALARM = "MusicAlarm"
535
535
  NOTIFICATION_REMINDER = "Reminder"
536
536
  NOTIFICATION_TIMER = "Timer"
537
+ NOTIFICATIONS_SUPPORTED = [
538
+ NOTIFICATION_ALARM,
539
+ NOTIFICATION_MUSIC_ALARM,
540
+ NOTIFICATION_REMINDER,
541
+ NOTIFICATION_TIMER,
542
+ ]