aioamazondevices 6.1.2__py3-none-any.whl → 6.2.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__ = "6.1.2"
3
+ __version__ = "6.2.0"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
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
@@ -29,6 +30,7 @@ from yarl import URL
29
30
  from . import __version__
30
31
  from .const import (
31
32
  _LOGGER,
33
+ ALEXA_INFO_SKILLS,
32
34
  AMAZON_APP_BUNDLE_ID,
33
35
  AMAZON_APP_ID,
34
36
  AMAZON_APP_NAME,
@@ -534,7 +536,7 @@ class AmazonEchoApi:
534
536
  input_data=body,
535
537
  json_data=True,
536
538
  )
537
- resp_json = await raw_resp.json()
539
+ resp_json = await self._response_to_json(raw_resp)
538
540
 
539
541
  if raw_resp.status != HTTPStatus.OK:
540
542
  msg = resp_json["response"]["error"]["message"]
@@ -599,7 +601,7 @@ class AmazonEchoApi:
599
601
  json_data=True,
600
602
  )
601
603
 
602
- return cast("dict", await raw_resp.json())
604
+ return await self._response_to_json(raw_resp)
603
605
 
604
606
  async def _get_sensors_states(
605
607
  self,
@@ -655,6 +657,19 @@ class AmazonEchoApi:
655
657
 
656
658
  return device_sensors
657
659
 
660
+ async def _response_to_json(self, raw_resp: ClientResponse) -> dict[str, Any]:
661
+ """Convert response to JSON, if possible."""
662
+ try:
663
+ data = await raw_resp.json(loads=orjson.loads)
664
+ if not data:
665
+ _LOGGER.warning("Empty JSON data received")
666
+ data = {}
667
+ return cast("dict[str, Any]", data)
668
+ except ContentTypeError as exc:
669
+ raise ValueError("Response not in JSON format") from exc
670
+ except orjson.JSONDecodeError as exc:
671
+ raise ValueError("Response with corrupted JSON format") from exc
672
+
658
673
  async def login_mode_interactive(self, otp_code: str) -> dict[str, Any]:
659
674
  """Login to Amazon interactively via OTP."""
660
675
  _LOGGER.debug(
@@ -756,7 +771,7 @@ class AmazonEchoApi:
756
771
  method=HTTPMethod.GET,
757
772
  url=f"https://alexa.amazon.{self._domain}/api/welcome",
758
773
  )
759
- json_data = await raw_resp.json()
774
+ json_data = await self._response_to_json(raw_resp)
760
775
  return cast(
761
776
  "str", json_data.get("alexaHostName", f"alexa.amazon.{self._domain}")
762
777
  )
@@ -802,8 +817,7 @@ class AmazonEchoApi:
802
817
  url=f"https://alexa.amazon.{self._domain}{URI_DEVICES}",
803
818
  )
804
819
 
805
- response_data = await raw_resp.text()
806
- json_data = {} if len(response_data) == 0 else await raw_resp.json()
820
+ json_data = await self._response_to_json(raw_resp)
807
821
 
808
822
  _LOGGER.debug("JSON devices data: %s", scrub_fields(json_data))
809
823
 
@@ -865,7 +879,7 @@ class AmazonEchoApi:
865
879
  )
866
880
  return False
867
881
 
868
- resp_json = await raw_resp.json()
882
+ resp_json = await self._response_to_json(raw_resp)
869
883
  if not (authentication := resp_json.get("authentication")):
870
884
  _LOGGER.debug('Session not authenticated: reply missing "authentication"')
871
885
  return False
@@ -985,6 +999,10 @@ class AmazonEchoApi:
985
999
  "uri": "connection://AMAZON.Launch/" + message_body,
986
1000
  },
987
1001
  }
1002
+ elif message_type in ALEXA_INFO_SKILLS:
1003
+ payload = {
1004
+ **base_payload,
1005
+ }
988
1006
  else:
989
1007
  raise ValueError(f"Message type <{message_type}> is not recognised")
990
1008
 
@@ -1075,6 +1093,14 @@ class AmazonEchoApi:
1075
1093
  device, AmazonSequenceType.LaunchSkill, message_body
1076
1094
  )
1077
1095
 
1096
+ async def call_alexa_info_skill(
1097
+ self,
1098
+ device: AmazonDevice,
1099
+ message_type: str,
1100
+ ) -> None:
1101
+ """Call Info skill. See ALEXA_INFO_SKILLS . const."""
1102
+ return await self._send_message(device, message_type, "")
1103
+
1078
1104
  async def set_do_not_disturb(self, device: AmazonDevice, state: bool) -> None:
1079
1105
  """Set do_not_disturb flag."""
1080
1106
  payload = {
@@ -1124,7 +1150,7 @@ class AmazonEchoApi:
1124
1150
  _LOGGER.debug("Failed to refresh data")
1125
1151
  return False, {}
1126
1152
 
1127
- json_response = await raw_resp.json()
1153
+ json_response = await self._response_to_json(raw_resp)
1128
1154
  _LOGGER.debug("Refresh data json:\n%s ", json_response)
1129
1155
 
1130
1156
  if data_type == REFRESH_ACCESS_TOKEN and (
@@ -1132,7 +1158,7 @@ class AmazonEchoApi:
1132
1158
  ):
1133
1159
  self._login_stored_data[REFRESH_ACCESS_TOKEN] = new_token
1134
1160
  self.expires_in = datetime.now(tz=UTC).timestamp() + int(
1135
- json_response.get("expires_in")
1161
+ json_response.get("expires_in", 0)
1136
1162
  )
1137
1163
  return True, json_response
1138
1164
 
aioamazondevices/const.py CHANGED
@@ -432,3 +432,23 @@ DEVICE_TYPE_TO_MODEL: dict[str, dict[str, str | None]] = {
432
432
  "hw_version": "Gen2",
433
433
  },
434
434
  }
435
+
436
+ ALEXA_INFO_SKILLS = [
437
+ "Alexa.Calendar.PlayToday",
438
+ "Alexa.Calendar.PlayTomorrow",
439
+ "Alexa.Calendar.PlayNext",
440
+ "Alexa.Date.Play",
441
+ "Alexa.Time.Play",
442
+ "Alexa.News.NationalNews",
443
+ "Alexa.FlashBriefing.Play",
444
+ "Alexa.Traffic.Play",
445
+ "Alexa.Weather.Play",
446
+ "Alexa.CleanUp.Play",
447
+ "Alexa.GoodMorning.Play",
448
+ "Alexa.SingASong.Play",
449
+ "Alexa.FunFact.Play",
450
+ "Alexa.Joke.Play",
451
+ "Alexa.TellStory.Play",
452
+ "Alexa.ImHome.Play",
453
+ "Alexa.GoodNight.Play",
454
+ ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: aioamazondevices
3
- Version: 6.1.2
3
+ Version: 6.2.0
4
4
  Summary: Python library to control Amazon devices
5
5
  License: Apache-2.0
6
6
  Author: Simone Chemelli
@@ -0,0 +1,12 @@
1
+ aioamazondevices/__init__.py,sha256=oT6YOexUE4rV5rAbI-rUuZ6XGk2jXwetnm_lzg-wTSU,276
2
+ aioamazondevices/api.py,sha256=spUjgxRW9qPKVzV9RwIX4QzkxrqwCrvM-MbdSxAE6u4,41973
3
+ aioamazondevices/const.py,sha256=38dhNRpwEJf0FgFQGjt3ONhLdQxjiNrnlcrmQ1AY8oU,11306
4
+ aioamazondevices/exceptions.py,sha256=JDnSFi_7oEhqK31sHXf0S_cyMoMjiRJuLp4ow7mYgLY,643
5
+ aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ aioamazondevices/query.py,sha256=AGHHzefzfYzB7RLWPtlFxYc_rpUZdoeApsU2jYz3urQ,2053
7
+ aioamazondevices/sounds.py,sha256=CXMDk-KoKVFxBdVAw3MeOClqgpzcVDxvQhFOJp7qX-Y,1896
8
+ aioamazondevices/utils.py,sha256=RzuKRhnq_8ymCoJMoQJ2vBYyuew06RSWpqQWmqdNczE,2019
9
+ aioamazondevices-6.2.0.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
10
+ aioamazondevices-6.2.0.dist-info/METADATA,sha256=HLWbqGs_h6-Jb-Ck5ojVO3S87c_KLT8MiuIbxAsOiU8,7623
11
+ aioamazondevices-6.2.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
12
+ aioamazondevices-6.2.0.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- aioamazondevices/__init__.py,sha256=E44EI2JWNaxJUHaUZZIdgRkO7_5H3ArkUwG6zQ4vuss,276
2
- aioamazondevices/api.py,sha256=43jaKpbMXNMsyR4iIvIW0FESlj7OhJMhaxcbLVFvvu0,40947
3
- aioamazondevices/const.py,sha256=bqJmaStichdm0zB1RQYXa4OPz2gU2JnmUFQHeItlnZE,10808
4
- aioamazondevices/exceptions.py,sha256=JDnSFi_7oEhqK31sHXf0S_cyMoMjiRJuLp4ow7mYgLY,643
5
- aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- aioamazondevices/query.py,sha256=AGHHzefzfYzB7RLWPtlFxYc_rpUZdoeApsU2jYz3urQ,2053
7
- aioamazondevices/sounds.py,sha256=CXMDk-KoKVFxBdVAw3MeOClqgpzcVDxvQhFOJp7qX-Y,1896
8
- aioamazondevices/utils.py,sha256=RzuKRhnq_8ymCoJMoQJ2vBYyuew06RSWpqQWmqdNczE,2019
9
- aioamazondevices-6.1.2.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
10
- aioamazondevices-6.1.2.dist-info/METADATA,sha256=CbbSegxCc24kR6kxciv61wBy4-ihMj5Rdbw0T6c-va0,7623
11
- aioamazondevices-6.1.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
12
- aioamazondevices-6.1.2.dist-info/RECORD,,