aioamazondevices 0.11.1__py3-none-any.whl → 0.13.0__py3-none-any.whl

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
  """aioamazondevices library."""
2
2
 
3
- __version__ = "0.11.1"
3
+ __version__ = "0.13.0"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
aioamazondevices/api.py CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  import base64
4
4
  import hashlib
5
- import json
6
5
  import mimetypes
7
6
  import secrets
8
7
  import uuid
@@ -29,10 +28,13 @@ from .const import (
29
28
  AMAZON_DEVICE_TYPE,
30
29
  DEFAULT_ASSOC_HANDLE,
31
30
  DEFAULT_HEADERS,
32
- DEVICES,
33
31
  DOMAIN_BY_COUNTRY,
34
32
  HTML_EXTENSION,
35
33
  JSON_EXTENSION,
34
+ NODE_BLUETOOTH,
35
+ NODE_DEVICES,
36
+ NODE_DO_NOT_DISTURB,
37
+ NODE_PREFERENCES,
36
38
  SAVE_PATH,
37
39
  URI_QUERIES,
38
40
  )
@@ -47,10 +49,11 @@ class AmazonDevice:
47
49
  capabilities: list[str]
48
50
  device_family: str
49
51
  device_type: str
52
+ online: bool
50
53
  serial_number: str
51
54
  software_version: str
52
55
  do_not_disturb: bool
53
- response_style: str
56
+ response_style: str | None
54
57
  bluetooth_state: bool
55
58
 
56
59
 
@@ -62,7 +65,7 @@ class AmazonEchoApi:
62
65
  login_country_code: str,
63
66
  login_email: str,
64
67
  login_password: str,
65
- login_data_file: str | None,
68
+ login_data: dict[str, Any] | None = None,
66
69
  save_raw_data: bool = False,
67
70
  ) -> None:
68
71
  """Initialize the scanner."""
@@ -85,24 +88,12 @@ class AmazonEchoApi:
85
88
  self._cookies = self._build_init_cookies()
86
89
  self._headers = DEFAULT_HEADERS
87
90
  self._save_raw_data = save_raw_data
88
- self._login_stored_data: dict[str, Any] = self._load_data_file(login_data_file)
91
+ self._login_stored_data = login_data
89
92
  self._serial = self._serial_number()
90
93
  self._website_cookies: dict[str, Any] = self._load_website_cookies()
91
94
 
92
95
  self.session: AsyncClient
93
96
 
94
- def _load_data_file(self, data_file: str | None) -> dict[str, Any]:
95
- """Load stored login data from file."""
96
- if not data_file or not (file := Path(data_file)).exists():
97
- _LOGGER.debug(
98
- "Cannot find previous login data file <%s>",
99
- data_file,
100
- )
101
- return {}
102
-
103
- with Path.open(file, "rb") as f:
104
- return cast(dict[str, Any], json.load(f))
105
-
106
97
  def _load_website_cookies(self) -> dict[str, Any]:
107
98
  """Get website cookies, if avaliables."""
108
99
  if not self._login_stored_data:
@@ -488,7 +479,7 @@ class AmazonEchoApi:
488
479
 
489
480
  async def get_devices_data(
490
481
  self,
491
- ) -> dict[str, Any]:
482
+ ) -> dict[str, AmazonDevice]:
492
483
  """Get Amazon devices data."""
493
484
  devices: dict[str, Any] = {}
494
485
  for key in URI_QUERIES:
@@ -513,13 +504,28 @@ class AmazonEchoApi:
513
504
  else:
514
505
  devices[dev_serial] = {key: data}
515
506
 
516
- # Remove stale, orphaned and virtual devices
517
- final_devices_list: dict[str, Any] = devices.copy()
518
- for serial, device in devices.items():
507
+ final_devices_list: dict[str, AmazonDevice] = {}
508
+ for device in devices.values():
509
+ # Remove stale, orphaned and virtual devices
519
510
  if (
520
- DEVICES not in device
521
- or device[DEVICES].get("deviceType") == AMAZON_DEVICE_TYPE
511
+ NODE_DEVICES not in device
512
+ or device[NODE_DEVICES].get("deviceType") == AMAZON_DEVICE_TYPE
522
513
  ):
523
- final_devices_list.pop(serial)
514
+ continue
515
+
516
+ serial_number: str = device[NODE_DEVICES]["serialNumber"]
517
+ preferences = device.get(NODE_PREFERENCES)
518
+ final_devices_list[serial_number] = AmazonDevice(
519
+ account_name=device[NODE_DEVICES]["accountName"],
520
+ capabilities=device[NODE_DEVICES]["capabilities"],
521
+ device_family=device[NODE_DEVICES]["deviceFamily"],
522
+ device_type=device[NODE_DEVICES]["deviceType"],
523
+ online=device[NODE_DEVICES]["online"],
524
+ serial_number=serial_number,
525
+ software_version=device[NODE_DEVICES]["softwareVersion"],
526
+ do_not_disturb=device[NODE_DO_NOT_DISTURB]["enabled"],
527
+ response_style=preferences["responseStyle"] if preferences else None,
528
+ bluetooth_state=device[NODE_BLUETOOTH]["online"],
529
+ )
524
530
 
525
531
  return final_devices_list
aioamazondevices/const.py CHANGED
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aioamazondevices
3
- Version: 0.11.1
3
+ Version: 0.13.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
@@ -0,0 +1,10 @@
1
+ aioamazondevices/__init__.py,sha256=6wV1gd7isgO5AUmPIAfBf15kyca8gwxV-r6OoIt1rJg,277
2
+ aioamazondevices/api.py,sha256=CpDap56Un4O8W19u9O9-Rr0CurTJWlwCyVWpNUvmyGE,19353
3
+ aioamazondevices/auth.py,sha256=vLJh7iOEUYu-44WOvmrmZZueOcwz5dmHAGQmqs9fJME,10099
4
+ aioamazondevices/const.py,sha256=pY3CTWW8mOaWbaDV_oZunX9hGcDZIhImzTXZEf-mXDU,1973
5
+ aioamazondevices/exceptions.py,sha256=qK_Hak9pc-lC2FPW-0i4rYIwNpEOHMmA9Rii8F2lkQo,1260
6
+ aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ aioamazondevices-0.13.0.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
8
+ aioamazondevices-0.13.0.dist-info/METADATA,sha256=3jik4PsdZwDzgKQoze9X98c-V4h9_NJ-RW0PIWV-cm4,4743
9
+ aioamazondevices-0.13.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
10
+ aioamazondevices-0.13.0.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- aioamazondevices/__init__.py,sha256=akBvRqfCUpiabNsm5jUMpv-R-f9w2wkuNvmSdisGhK0,277
2
- aioamazondevices/api.py,sha256=bDKV6Tb55WfZusA1e5FogHP4Ig3n5i03ufbdzg4XYvw,18880
3
- aioamazondevices/auth.py,sha256=vLJh7iOEUYu-44WOvmrmZZueOcwz5dmHAGQmqs9fJME,10099
4
- aioamazondevices/const.py,sha256=T143A-tHoBTjIocWin9q4BQ_2kUozj-EwWGba3RoqSs,1852
5
- aioamazondevices/exceptions.py,sha256=qK_Hak9pc-lC2FPW-0i4rYIwNpEOHMmA9Rii8F2lkQo,1260
6
- aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- aioamazondevices-0.11.1.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
8
- aioamazondevices-0.11.1.dist-info/METADATA,sha256=d4SrpvMAaTUaiGR6l0e7YkbAoHr4ozg9tL1cPCZOxp8,4743
9
- aioamazondevices-0.11.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
10
- aioamazondevices-0.11.1.dist-info/RECORD,,