aioamazondevices 0.11.1__tar.gz → 0.13.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.
- {aioamazondevices-0.11.1 → aioamazondevices-0.13.0}/PKG-INFO +1 -1
- {aioamazondevices-0.11.1 → aioamazondevices-0.13.0}/pyproject.toml +1 -1
- {aioamazondevices-0.11.1 → aioamazondevices-0.13.0}/src/aioamazondevices/__init__.py +1 -1
- {aioamazondevices-0.11.1 → aioamazondevices-0.13.0}/src/aioamazondevices/api.py +30 -24
- {aioamazondevices-0.11.1 → aioamazondevices-0.13.0}/src/aioamazondevices/const.py +9 -5
- {aioamazondevices-0.11.1 → aioamazondevices-0.13.0}/LICENSE +0 -0
- {aioamazondevices-0.11.1 → aioamazondevices-0.13.0}/README.md +0 -0
- {aioamazondevices-0.11.1 → aioamazondevices-0.13.0}/src/aioamazondevices/auth.py +0 -0
- {aioamazondevices-0.11.1 → aioamazondevices-0.13.0}/src/aioamazondevices/exceptions.py +0 -0
- {aioamazondevices-0.11.1 → aioamazondevices-0.13.0}/src/aioamazondevices/py.typed +0 -0
@@ -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
|
-
|
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
|
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,
|
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
|
-
|
517
|
-
|
518
|
-
|
507
|
+
final_devices_list: dict[str, AmazonDevice] = {}
|
508
|
+
for device in devices.values():
|
509
|
+
# Remove stale, orphaned and virtual devices
|
519
510
|
if (
|
520
|
-
|
521
|
-
or device[
|
511
|
+
NODE_DEVICES not in device
|
512
|
+
or device[NODE_DEVICES].get("deviceType") == AMAZON_DEVICE_TYPE
|
522
513
|
):
|
523
|
-
|
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
|
@@ -44,12 +44,16 @@ DEFAULT_HEADERS = {
|
|
44
44
|
"Accept-Encoding": "gzip",
|
45
45
|
}
|
46
46
|
|
47
|
-
|
47
|
+
NODE_DEVICES = "devices"
|
48
|
+
NODE_DO_NOT_DISTURB = "doNotDisturbDeviceStatusList"
|
49
|
+
NODE_PREFERENCES = "devicePreferences"
|
50
|
+
NODE_BLUETOOTH = "bluetoothStates"
|
51
|
+
|
48
52
|
URI_QUERIES = {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|