aioamazondevices 0.11.1__tar.gz → 0.12.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.1
2
2
  Name: aioamazondevices
3
- Version: 0.11.1
3
+ Version: 0.12.0
4
4
  Summary: Python library to control Amazon devices
5
5
  Home-page: https://github.com/chemelli74/aioamazondevices
6
6
  License: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "aioamazondevices"
3
- version = "0.11.1"
3
+ version = "0.12.0"
4
4
  description = "Python library to control Amazon devices"
5
5
  authors = ["Simone Chemelli <simone.chemelli@gmail.com>"]
6
6
  license = "Apache-2.0"
@@ -1,6 +1,6 @@
1
1
  """aioamazondevices library."""
2
2
 
3
- __version__ = "0.11.1"
3
+ __version__ = "0.12.0"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
@@ -29,10 +29,13 @@ from .const import (
29
29
  AMAZON_DEVICE_TYPE,
30
30
  DEFAULT_ASSOC_HANDLE,
31
31
  DEFAULT_HEADERS,
32
- DEVICES,
33
32
  DOMAIN_BY_COUNTRY,
34
33
  HTML_EXTENSION,
35
34
  JSON_EXTENSION,
35
+ NODE_BLUETOOTH,
36
+ NODE_DEVICES,
37
+ NODE_DO_NOT_DISTURB,
38
+ NODE_PREFERENCES,
36
39
  SAVE_PATH,
37
40
  URI_QUERIES,
38
41
  )
@@ -47,10 +50,11 @@ class AmazonDevice:
47
50
  capabilities: list[str]
48
51
  device_family: str
49
52
  device_type: str
53
+ online: bool
50
54
  serial_number: str
51
55
  software_version: str
52
56
  do_not_disturb: bool
53
- response_style: str
57
+ response_style: str | None
54
58
  bluetooth_state: bool
55
59
 
56
60
 
@@ -488,7 +492,7 @@ class AmazonEchoApi:
488
492
 
489
493
  async def get_devices_data(
490
494
  self,
491
- ) -> dict[str, Any]:
495
+ ) -> dict[str, AmazonDevice]:
492
496
  """Get Amazon devices data."""
493
497
  devices: dict[str, Any] = {}
494
498
  for key in URI_QUERIES:
@@ -513,13 +517,28 @@ class AmazonEchoApi:
513
517
  else:
514
518
  devices[dev_serial] = {key: data}
515
519
 
516
- # Remove stale, orphaned and virtual devices
517
- final_devices_list: dict[str, Any] = devices.copy()
518
- for serial, device in devices.items():
520
+ final_devices_list: dict[str, AmazonDevice] = {}
521
+ for device in devices.values():
522
+ # Remove stale, orphaned and virtual devices
519
523
  if (
520
- DEVICES not in device
521
- or device[DEVICES].get("deviceType") == AMAZON_DEVICE_TYPE
524
+ NODE_DEVICES not in device
525
+ or device[NODE_DEVICES].get("deviceType") == AMAZON_DEVICE_TYPE
522
526
  ):
523
- final_devices_list.pop(serial)
527
+ continue
528
+
529
+ serial_number: str = device[NODE_DEVICES]["serialNumber"]
530
+ preferences = device.get(NODE_PREFERENCES)
531
+ final_devices_list[serial_number] = AmazonDevice(
532
+ account_name=device[NODE_DEVICES]["accountName"],
533
+ capabilities=device[NODE_DEVICES]["capabilities"],
534
+ device_family=device[NODE_DEVICES]["deviceFamily"],
535
+ device_type=device[NODE_DEVICES]["deviceType"],
536
+ online=device[NODE_DEVICES]["online"],
537
+ serial_number=serial_number,
538
+ software_version=device[NODE_DEVICES]["softwareVersion"],
539
+ do_not_disturb=device[NODE_DO_NOT_DISTURB]["enabled"],
540
+ response_style=preferences["responseStyle"] if preferences else None,
541
+ bluetooth_state=device[NODE_BLUETOOTH]["online"],
542
+ )
524
543
 
525
544
  return final_devices_list
@@ -44,12 +44,16 @@ DEFAULT_HEADERS = {
44
44
  "Accept-Encoding": "gzip",
45
45
  }
46
46
 
47
- DEVICES = "devices"
47
+ NODE_DEVICES = "devices"
48
+ NODE_DO_NOT_DISTURB = "doNotDisturbDeviceStatusList"
49
+ NODE_PREFERENCES = "devicePreferences"
50
+ NODE_BLUETOOTH = "bluetoothStates"
51
+
48
52
  URI_QUERIES = {
49
- DEVICES: "/api/devices-v2/device",
50
- "doNotDisturbDeviceStatusList": "/api/dnd/device-status-list",
51
- "devicePreferences": "/api/device-preferences",
52
- "bluetoothStates": "/api/bluetooth",
53
+ NODE_DEVICES: "/api/devices-v2/device",
54
+ NODE_DO_NOT_DISTURB: "/api/dnd/device-status-list",
55
+ NODE_PREFERENCES: "/api/device-preferences",
56
+ NODE_BLUETOOTH: "/api/bluetooth",
53
57
  }
54
58
 
55
59
  # File extensions