aioamazondevices 6.1.2__py3-none-any.whl → 6.1.3__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.
- aioamazondevices/__init__.py +1 -1
- aioamazondevices/api.py +21 -8
- {aioamazondevices-6.1.2.dist-info → aioamazondevices-6.1.3.dist-info}/METADATA +1 -1
- {aioamazondevices-6.1.2.dist-info → aioamazondevices-6.1.3.dist-info}/RECORD +6 -6
- {aioamazondevices-6.1.2.dist-info → aioamazondevices-6.1.3.dist-info}/LICENSE +0 -0
- {aioamazondevices-6.1.2.dist-info → aioamazondevices-6.1.3.dist-info}/WHEEL +0 -0
aioamazondevices/__init__.py
CHANGED
aioamazondevices/api.py
CHANGED
@@ -20,6 +20,7 @@ from aiohttp import (
|
|
20
20
|
ClientConnectorError,
|
21
21
|
ClientResponse,
|
22
22
|
ClientSession,
|
23
|
+
ContentTypeError,
|
23
24
|
)
|
24
25
|
from bs4 import BeautifulSoup, Tag
|
25
26
|
from langcodes import Language, standardize_tag
|
@@ -534,7 +535,7 @@ class AmazonEchoApi:
|
|
534
535
|
input_data=body,
|
535
536
|
json_data=True,
|
536
537
|
)
|
537
|
-
resp_json = await
|
538
|
+
resp_json = await self._response_to_json(raw_resp)
|
538
539
|
|
539
540
|
if raw_resp.status != HTTPStatus.OK:
|
540
541
|
msg = resp_json["response"]["error"]["message"]
|
@@ -599,7 +600,7 @@ class AmazonEchoApi:
|
|
599
600
|
json_data=True,
|
600
601
|
)
|
601
602
|
|
602
|
-
return
|
603
|
+
return await self._response_to_json(raw_resp)
|
603
604
|
|
604
605
|
async def _get_sensors_states(
|
605
606
|
self,
|
@@ -655,6 +656,19 @@ class AmazonEchoApi:
|
|
655
656
|
|
656
657
|
return device_sensors
|
657
658
|
|
659
|
+
async def _response_to_json(self, raw_resp: ClientResponse) -> dict[str, Any]:
|
660
|
+
"""Convert response to JSON, if possible."""
|
661
|
+
try:
|
662
|
+
data = await raw_resp.json(loads=orjson.loads)
|
663
|
+
if not data:
|
664
|
+
_LOGGER.warning("Empty JSON data received")
|
665
|
+
data = {}
|
666
|
+
return cast("dict[str, Any]", data)
|
667
|
+
except ContentTypeError as exc:
|
668
|
+
raise ValueError("Response not in JSON format") from exc
|
669
|
+
except orjson.JSONDecodeError as exc:
|
670
|
+
raise ValueError("Response with corrupted JSON format") from exc
|
671
|
+
|
658
672
|
async def login_mode_interactive(self, otp_code: str) -> dict[str, Any]:
|
659
673
|
"""Login to Amazon interactively via OTP."""
|
660
674
|
_LOGGER.debug(
|
@@ -756,7 +770,7 @@ class AmazonEchoApi:
|
|
756
770
|
method=HTTPMethod.GET,
|
757
771
|
url=f"https://alexa.amazon.{self._domain}/api/welcome",
|
758
772
|
)
|
759
|
-
json_data = await
|
773
|
+
json_data = await self._response_to_json(raw_resp)
|
760
774
|
return cast(
|
761
775
|
"str", json_data.get("alexaHostName", f"alexa.amazon.{self._domain}")
|
762
776
|
)
|
@@ -802,8 +816,7 @@ class AmazonEchoApi:
|
|
802
816
|
url=f"https://alexa.amazon.{self._domain}{URI_DEVICES}",
|
803
817
|
)
|
804
818
|
|
805
|
-
|
806
|
-
json_data = {} if len(response_data) == 0 else await raw_resp.json()
|
819
|
+
json_data = await self._response_to_json(raw_resp)
|
807
820
|
|
808
821
|
_LOGGER.debug("JSON devices data: %s", scrub_fields(json_data))
|
809
822
|
|
@@ -865,7 +878,7 @@ class AmazonEchoApi:
|
|
865
878
|
)
|
866
879
|
return False
|
867
880
|
|
868
|
-
resp_json = await
|
881
|
+
resp_json = await self._response_to_json(raw_resp)
|
869
882
|
if not (authentication := resp_json.get("authentication")):
|
870
883
|
_LOGGER.debug('Session not authenticated: reply missing "authentication"')
|
871
884
|
return False
|
@@ -1124,7 +1137,7 @@ class AmazonEchoApi:
|
|
1124
1137
|
_LOGGER.debug("Failed to refresh data")
|
1125
1138
|
return False, {}
|
1126
1139
|
|
1127
|
-
json_response = await
|
1140
|
+
json_response = await self._response_to_json(raw_resp)
|
1128
1141
|
_LOGGER.debug("Refresh data json:\n%s ", json_response)
|
1129
1142
|
|
1130
1143
|
if data_type == REFRESH_ACCESS_TOKEN and (
|
@@ -1132,7 +1145,7 @@ class AmazonEchoApi:
|
|
1132
1145
|
):
|
1133
1146
|
self._login_stored_data[REFRESH_ACCESS_TOKEN] = new_token
|
1134
1147
|
self.expires_in = datetime.now(tz=UTC).timestamp() + int(
|
1135
|
-
json_response.get("expires_in")
|
1148
|
+
json_response.get("expires_in", 0)
|
1136
1149
|
)
|
1137
1150
|
return True, json_response
|
1138
1151
|
|
@@ -1,12 +1,12 @@
|
|
1
|
-
aioamazondevices/__init__.py,sha256=
|
2
|
-
aioamazondevices/api.py,sha256=
|
1
|
+
aioamazondevices/__init__.py,sha256=xeVWui7vweRIpKp3JwYLPcG-tXnRhz-cFfImDeXVFWU,276
|
2
|
+
aioamazondevices/api.py,sha256=C4XD9GvRmwL-sc-dRlaWzarlLzeqq8N4rTymCdyF0-Q,41579
|
3
3
|
aioamazondevices/const.py,sha256=bqJmaStichdm0zB1RQYXa4OPz2gU2JnmUFQHeItlnZE,10808
|
4
4
|
aioamazondevices/exceptions.py,sha256=JDnSFi_7oEhqK31sHXf0S_cyMoMjiRJuLp4ow7mYgLY,643
|
5
5
|
aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
6
|
aioamazondevices/query.py,sha256=AGHHzefzfYzB7RLWPtlFxYc_rpUZdoeApsU2jYz3urQ,2053
|
7
7
|
aioamazondevices/sounds.py,sha256=CXMDk-KoKVFxBdVAw3MeOClqgpzcVDxvQhFOJp7qX-Y,1896
|
8
8
|
aioamazondevices/utils.py,sha256=RzuKRhnq_8ymCoJMoQJ2vBYyuew06RSWpqQWmqdNczE,2019
|
9
|
-
aioamazondevices-6.1.
|
10
|
-
aioamazondevices-6.1.
|
11
|
-
aioamazondevices-6.1.
|
12
|
-
aioamazondevices-6.1.
|
9
|
+
aioamazondevices-6.1.3.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
|
10
|
+
aioamazondevices-6.1.3.dist-info/METADATA,sha256=WBhhAbei9OCzT63keD7HIoOVOnmu3Vy2EqitmtTEADQ,7623
|
11
|
+
aioamazondevices-6.1.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
12
|
+
aioamazondevices-6.1.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|