aioamazondevices 0.7.3__py3-none-any.whl → 0.9.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.7.3"
3
+ __version__ = "0.9.0"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
aioamazondevices/api.py CHANGED
@@ -28,6 +28,7 @@ from .const import (
28
28
  AMAZON_DEVICE_TYPE,
29
29
  DEFAULT_ASSOC_HANDLE,
30
30
  DEFAULT_HEADERS,
31
+ DEVICES,
31
32
  DOMAIN_BY_COUNTRY,
32
33
  HTML_EXTENSION,
33
34
  JSON_EXTENSION,
@@ -58,7 +59,7 @@ class AmazonEchoApi:
58
59
  login_country_code: str,
59
60
  login_email: str,
60
61
  login_password: str,
61
- save_html: bool = False,
62
+ save_raw_data: bool = False,
62
63
  ) -> None:
63
64
  """Initialize the scanner."""
64
65
  # Force country digits as lower case
@@ -79,7 +80,7 @@ class AmazonEchoApi:
79
80
  self._url = f"https://www.amazon.{domain}"
80
81
  self._cookies = self._build_init_cookies()
81
82
  self._headers = DEFAULT_HEADERS
82
- self._save_html = save_html
83
+ self._save_raw_data = save_raw_data
83
84
  self._serial = self._serial_number()
84
85
 
85
86
  self.session: AsyncClient
@@ -235,7 +236,7 @@ class AmazonEchoApi:
235
236
  output_path: str = SAVE_PATH,
236
237
  ) -> None:
237
238
  """Save response data to disk."""
238
- if not self._save_html:
239
+ if not self._save_raw_data:
239
240
  return
240
241
 
241
242
  output_dir = Path(output_path)
@@ -441,7 +442,7 @@ class AmazonEchoApi:
441
442
  self,
442
443
  ) -> dict[str, Any]:
443
444
  """Get Amazon devices data."""
444
- devices = {}
445
+ devices: dict[str, Any] = {}
445
446
  for key in URI_QUERIES:
446
447
  _, raw_resp = await self._session_request(
447
448
  "GET",
@@ -457,10 +458,21 @@ class AmazonEchoApi:
457
458
 
458
459
  _LOGGER.debug("JSON data: |%s|", json_data)
459
460
 
460
- devices.update(
461
- {
462
- key: json_data,
463
- },
464
- )
465
-
466
- return devices
461
+ for data in json_data[key]:
462
+ dev_serial = data.get("serialNumber") or data.get("deviceSerialNumber")
463
+ if previous_data := devices.get(dev_serial):
464
+ devices[dev_serial] = previous_data | {key: data}
465
+ else:
466
+ devices[dev_serial] = {key: data}
467
+
468
+ # Remove stale, orphaned and virtual devices
469
+ final_devices_list: dict[str, Any] = devices.copy()
470
+ for serial in devices:
471
+ device = devices[serial]
472
+ if (
473
+ DEVICES not in device
474
+ or device[DEVICES].get("deviceType") == AMAZON_DEVICE_TYPE
475
+ ):
476
+ final_devices_list.pop(serial)
477
+
478
+ return final_devices_list
aioamazondevices/const.py CHANGED
@@ -35,12 +35,12 @@ DEFAULT_HEADERS = {
35
35
  "Accept-Encoding": "gzip",
36
36
  }
37
37
 
38
+ DEVICES = "devices"
38
39
  URI_QUERIES = {
39
- "base": "/api/devices-v2/device",
40
- "status": "/api/dnd/device-status-list",
41
- "preferences": "/api/device-preferences",
42
- "automations": "/api/behaviors/v2/automations",
43
- "bluetooth": "/api/bluetooth",
40
+ DEVICES: "/api/devices-v2/device",
41
+ "doNotDisturbDeviceStatusList": "/api/dnd/device-status-list",
42
+ "devicePreferences": "/api/device-preferences",
43
+ "bluetoothStates": "/api/bluetooth",
44
44
  }
45
45
 
46
46
  # Amazon APP info
@@ -1,19 +1,18 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aioamazondevices
3
- Version: 0.7.3
3
+ Version: 0.9.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
7
7
  Author: Simone Chemelli
8
8
  Author-email: simone.chemelli@gmail.com
9
- Requires-Python: >=3.11,<4.0
9
+ Requires-Python: >=3.12,<4.0
10
10
  Classifier: Development Status :: 2 - Pre-Alpha
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Natural Language :: English
14
14
  Classifier: Operating System :: OS Independent
15
15
  Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3.11
17
16
  Classifier: Programming Language :: Python :: 3.12
18
17
  Classifier: Programming Language :: Python :: 3.13
19
18
  Classifier: Topic :: Software Development :: Libraries
@@ -0,0 +1,9 @@
1
+ aioamazondevices/__init__.py,sha256=uvo6LseWC7RF7rLYW5_5MxB9lsIE-azOJqwDtdoZmY4,276
2
+ aioamazondevices/api.py,sha256=5WuQuXi0TX6pjuZBn5JcqPPNUe43E8FnLhSmYGfe4vE,17168
3
+ aioamazondevices/const.py,sha256=MJYY90iUDvj1x3MKEh5RQoflQ-ftnIp0YvJLTSemGEI,1351
4
+ aioamazondevices/exceptions.py,sha256=yQ9nL4UwBdHNXvdRj8TRemed6PXBmExP8lbHaAp04vY,546
5
+ aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ aioamazondevices-0.9.0.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
7
+ aioamazondevices-0.9.0.dist-info/METADATA,sha256=apvr3suIW9DI-5_lw2K8YBnsuq38jdV9v61V9EsYc6s,4701
8
+ aioamazondevices-0.9.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
9
+ aioamazondevices-0.9.0.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- aioamazondevices/__init__.py,sha256=43R_n8z8MnmFxV1nrDOdsTWDjs61LdB_GbYMBmN1YTU,276
2
- aioamazondevices/api.py,sha256=3eagygo9Kx1Qx2v602wZW6MyCTuA5Tmq545TmGX6zWc,16518
3
- aioamazondevices/const.py,sha256=BnA9rU9S9vH9mmmE-In443PECLUmGll9-iWu-oETo4s,1348
4
- aioamazondevices/exceptions.py,sha256=yQ9nL4UwBdHNXvdRj8TRemed6PXBmExP8lbHaAp04vY,546
5
- aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- aioamazondevices-0.7.3.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
7
- aioamazondevices-0.7.3.dist-info/METADATA,sha256=u9bchAmH6hMggC3zHTUDMR7phel-64dmrv9ptUdp0vE,4752
8
- aioamazondevices-0.7.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
9
- aioamazondevices-0.7.3.dist-info/RECORD,,