aioamazondevices 1.5.0__tar.gz → 1.6.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: aioamazondevices
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: Python library to control Amazon devices
5
5
  License: Apache-2.0
6
6
  Author: Simone Chemelli
@@ -82,8 +82,8 @@ The script accept command line arguments or a library_test.json config file:
82
82
  "country": "IT",
83
83
  "email": "<my_address@gmail.com>",
84
84
  "password": "<my_password>",
85
- "device_name_speak": "Echo Dot Livingroom",
86
- "device_name_announcement": "Everywhere",
85
+ "single_device_name": "Echo Dot Livingroom",
86
+ "cluster_device_name": "Everywhere",
87
87
  "login_data_file": "out/login_data.json",
88
88
  "save_raw_data": "True"
89
89
  }
@@ -54,8 +54,8 @@ The script accept command line arguments or a library_test.json config file:
54
54
  "country": "IT",
55
55
  "email": "<my_address@gmail.com>",
56
56
  "password": "<my_password>",
57
- "device_name_speak": "Echo Dot Livingroom",
58
- "device_name_announcement": "Everywhere",
57
+ "single_device_name": "Echo Dot Livingroom",
58
+ "cluster_device_name": "Everywhere",
59
59
  "login_data_file": "out/login_data.json",
60
60
  "save_raw_data": "True"
61
61
  }
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "aioamazondevices"
3
- version = "1.5.0"
3
+ version = "1.6.0"
4
4
  description = "Python library to control Amazon devices"
5
5
  authors = ["Simone Chemelli <simone.chemelli@gmail.com>"]
6
6
  license = "Apache-2.0"
@@ -1,6 +1,6 @@
1
1
  """aioamazondevices library."""
2
2
 
3
- __version__ = "1.5.0"
3
+ __version__ = "1.6.0"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
@@ -7,6 +7,7 @@ import secrets
7
7
  import uuid
8
8
  from dataclasses import dataclass
9
9
  from datetime import UTC, datetime, timedelta
10
+ from enum import StrEnum
10
11
  from http import HTTPStatus
11
12
  from http.cookies import Morsel
12
13
  from pathlib import Path
@@ -63,6 +64,14 @@ class AmazonDevice:
63
64
  bluetooth_state: bool
64
65
 
65
66
 
67
+ class AmazonSequenceType(StrEnum):
68
+ """Amazon sequence types."""
69
+
70
+ Announcement = "AlexaAnnouncement"
71
+ Speak = "Alexa.Speak"
72
+ Sound = "Alexa.Sound"
73
+
74
+
66
75
  class AmazonEchoApi:
67
76
  """Queries Amazon for Echo devices."""
68
77
 
@@ -611,13 +620,17 @@ class AmazonEchoApi:
611
620
  _LOGGER.warning("Trying to send message before login")
612
621
  return
613
622
 
623
+ base_payload = {
624
+ "deviceType": device.device_type,
625
+ "deviceSerialNumber": device.serial_number,
626
+ "locale": locale,
627
+ "customerId": device.device_owner_customer_id,
628
+ }
629
+
614
630
  payload: dict[str, Any]
615
- if message_type == "Alexa.Speak":
631
+ if message_type == AmazonSequenceType.Speak:
616
632
  payload = {
617
- "deviceType": device.device_type,
618
- "deviceSerialNumber": device.serial_number,
619
- "locale": locale,
620
- "customerId": device.device_owner_customer_id,
633
+ **base_payload,
621
634
  "textToSpeak": message_body,
622
635
  "target": {
623
636
  "customerId": device.device_owner_customer_id,
@@ -630,7 +643,7 @@ class AmazonEchoApi:
630
643
  },
631
644
  "skillId": "amzn1.ask.1p.saysomething",
632
645
  }
633
- else:
646
+ elif message_type == AmazonSequenceType.Announcement:
634
647
  playback_devices: list[dict[str, str]] = [
635
648
  {
636
649
  "deviceSerialNumber": serial,
@@ -641,10 +654,7 @@ class AmazonEchoApi:
641
654
  ]
642
655
 
643
656
  payload = {
644
- "deviceType": device.device_type,
645
- "deviceSerialNumber": device.serial_number,
646
- "locale": locale,
647
- "customerId": device.device_owner_customer_id,
657
+ **base_payload,
648
658
  "expireAfter": "PT5S",
649
659
  "content": [
650
660
  {
@@ -665,6 +675,12 @@ class AmazonEchoApi:
665
675
  },
666
676
  "skillId": "amzn1.ask.1p.routines.messaging",
667
677
  }
678
+ elif message_type == AmazonSequenceType.Sound:
679
+ payload = {
680
+ **base_payload,
681
+ "soundStringId": message_body,
682
+ "skillId": "amzn1.ask.1p.sound",
683
+ }
668
684
 
669
685
  sequence = {
670
686
  "@type": "com.amazon.alexa.behaviors.model.Sequence",
@@ -702,7 +718,7 @@ class AmazonEchoApi:
702
718
  message_body: str,
703
719
  ) -> None:
704
720
  """Call Alexa.Speak to send a message."""
705
- return await self._send_message(device, "Alexa.Speak", message_body)
721
+ return await self._send_message(device, AmazonSequenceType.Speak, message_body)
706
722
 
707
723
  async def call_alexa_announcement(
708
724
  self,
@@ -710,4 +726,14 @@ class AmazonEchoApi:
710
726
  message_body: str,
711
727
  ) -> None:
712
728
  """Call AlexaAnnouncement to send a message."""
713
- return await self._send_message(device, "AlexaAnnouncement", message_body)
729
+ return await self._send_message(
730
+ device, AmazonSequenceType.Announcement, message_body
731
+ )
732
+
733
+ async def call_alexa_sound(
734
+ self,
735
+ device: AmazonDevice,
736
+ message_body: str,
737
+ ) -> None:
738
+ """Call Alexa.Sound to send a message."""
739
+ return await self._send_message(device, AmazonSequenceType.Sound, message_body)