aioamazondevices 0.11.0__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.0
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.0"
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.0"
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
  )
@@ -43,13 +46,16 @@ from .exceptions import CannotAuthenticate, CannotRegisterDevice, WrongMethod
43
46
  class AmazonDevice:
44
47
  """Amazon device class."""
45
48
 
46
- connected: bool
47
- connection_type: str
48
- ip_address: str
49
- name: str
50
- mac: str
51
- type: str
52
- wifi: str
49
+ account_name: str
50
+ capabilities: list[str]
51
+ device_family: str
52
+ device_type: str
53
+ online: bool
54
+ serial_number: str
55
+ software_version: str
56
+ do_not_disturb: bool
57
+ response_style: str | None
58
+ bluetooth_state: bool
53
59
 
54
60
 
55
61
  class AmazonEchoApi:
@@ -486,7 +492,7 @@ class AmazonEchoApi:
486
492
 
487
493
  async def get_devices_data(
488
494
  self,
489
- ) -> dict[str, Any]:
495
+ ) -> dict[str, AmazonDevice]:
490
496
  """Get Amazon devices data."""
491
497
  devices: dict[str, Any] = {}
492
498
  for key in URI_QUERIES:
@@ -511,13 +517,28 @@ class AmazonEchoApi:
511
517
  else:
512
518
  devices[dev_serial] = {key: data}
513
519
 
514
- # Remove stale, orphaned and virtual devices
515
- final_devices_list: dict[str, Any] = devices.copy()
516
- 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
517
523
  if (
518
- DEVICES not in device
519
- or device[DEVICES].get("deviceType") == AMAZON_DEVICE_TYPE
524
+ NODE_DEVICES not in device
525
+ or device[NODE_DEVICES].get("deviceType") == AMAZON_DEVICE_TYPE
520
526
  ):
521
- 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
+ )
522
543
 
523
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