aioamazondevices 1.5.0__tar.gz → 1.7.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.7.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.7.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.7.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,22 @@ 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
+ Music = "Alexa.Music.PlaySearchPhrase"
74
+
75
+
76
+ class AmazonMusicSource(StrEnum):
77
+ """Amazon music sources."""
78
+
79
+ Radio = "TUNEIN"
80
+ AmazonMusic = "AMAZON_MUSIC"
81
+
82
+
66
83
  class AmazonEchoApi:
67
84
  """Queries Amazon for Echo devices."""
68
85
 
@@ -601,7 +618,11 @@ class AmazonEchoApi:
601
618
  return bool(authenticated)
602
619
 
603
620
  async def _send_message(
604
- self, device: AmazonDevice, message_type: str, message_body: str
621
+ self,
622
+ device: AmazonDevice,
623
+ message_type: str,
624
+ message_body: str,
625
+ message_source: AmazonMusicSource | None = None,
605
626
  ) -> None:
606
627
  """Send message to specific device."""
607
628
  locale_data = Locale.parse(f"und_{self._login_country_code}")
@@ -611,13 +632,17 @@ class AmazonEchoApi:
611
632
  _LOGGER.warning("Trying to send message before login")
612
633
  return
613
634
 
635
+ base_payload = {
636
+ "deviceType": device.device_type,
637
+ "deviceSerialNumber": device.serial_number,
638
+ "locale": locale,
639
+ "customerId": device.device_owner_customer_id,
640
+ }
641
+
614
642
  payload: dict[str, Any]
615
- if message_type == "Alexa.Speak":
643
+ if message_type == AmazonSequenceType.Speak:
616
644
  payload = {
617
- "deviceType": device.device_type,
618
- "deviceSerialNumber": device.serial_number,
619
- "locale": locale,
620
- "customerId": device.device_owner_customer_id,
645
+ **base_payload,
621
646
  "textToSpeak": message_body,
622
647
  "target": {
623
648
  "customerId": device.device_owner_customer_id,
@@ -630,7 +655,7 @@ class AmazonEchoApi:
630
655
  },
631
656
  "skillId": "amzn1.ask.1p.saysomething",
632
657
  }
633
- else:
658
+ elif message_type == AmazonSequenceType.Announcement:
634
659
  playback_devices: list[dict[str, str]] = [
635
660
  {
636
661
  "deviceSerialNumber": serial,
@@ -641,10 +666,7 @@ class AmazonEchoApi:
641
666
  ]
642
667
 
643
668
  payload = {
644
- "deviceType": device.device_type,
645
- "deviceSerialNumber": device.serial_number,
646
- "locale": locale,
647
- "customerId": device.device_owner_customer_id,
669
+ **base_payload,
648
670
  "expireAfter": "PT5S",
649
671
  "content": [
650
672
  {
@@ -665,6 +687,19 @@ class AmazonEchoApi:
665
687
  },
666
688
  "skillId": "amzn1.ask.1p.routines.messaging",
667
689
  }
690
+ elif message_type == AmazonSequenceType.Sound:
691
+ payload = {
692
+ **base_payload,
693
+ "soundStringId": message_body,
694
+ "skillId": "amzn1.ask.1p.sound",
695
+ }
696
+ elif message_type == AmazonSequenceType.Music:
697
+ payload = {
698
+ **base_payload,
699
+ "searchPhrase": message_body,
700
+ "sanitizedSearchPhrase": message_body,
701
+ "musicProviderId": message_source,
702
+ }
668
703
 
669
704
  sequence = {
670
705
  "@type": "com.amazon.alexa.behaviors.model.Sequence",
@@ -702,7 +737,7 @@ class AmazonEchoApi:
702
737
  message_body: str,
703
738
  ) -> None:
704
739
  """Call Alexa.Speak to send a message."""
705
- return await self._send_message(device, "Alexa.Speak", message_body)
740
+ return await self._send_message(device, AmazonSequenceType.Speak, message_body)
706
741
 
707
742
  async def call_alexa_announcement(
708
743
  self,
@@ -710,4 +745,25 @@ class AmazonEchoApi:
710
745
  message_body: str,
711
746
  ) -> None:
712
747
  """Call AlexaAnnouncement to send a message."""
713
- return await self._send_message(device, "AlexaAnnouncement", message_body)
748
+ return await self._send_message(
749
+ device, AmazonSequenceType.Announcement, message_body
750
+ )
751
+
752
+ async def call_alexa_sound(
753
+ self,
754
+ device: AmazonDevice,
755
+ message_body: str,
756
+ ) -> None:
757
+ """Call Alexa.Sound to play sound."""
758
+ return await self._send_message(device, AmazonSequenceType.Sound, message_body)
759
+
760
+ async def call_alexa_music(
761
+ self,
762
+ device: AmazonDevice,
763
+ message_body: str,
764
+ message_source: AmazonMusicSource,
765
+ ) -> None:
766
+ """Call Alexa.Music.PlaySearchPhrase to play music."""
767
+ return await self._send_message(
768
+ device, AmazonSequenceType.Music, message_body, message_source
769
+ )