python-amazon-echo 0.3.0__tar.gz → 0.3.2__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.
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/CHANGELOG.md +16 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/PKG-INFO +9 -6
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/README.md +8 -5
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/pyproject.toml +1 -1
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/src/amazon_echo/__init__.py +1 -1
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/src/amazon_echo/client.py +63 -21
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/src/amazon_echo/const.py +1 -1
- python_amazon_echo-0.3.2/src/amazon_echo/phrases.py +128 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/test_client.py +81 -11
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/test_models.py +1 -1
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/.gitignore +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/LICENSE +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/src/amazon_echo/__main__.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/src/amazon_echo/auth.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/src/amazon_echo/endpoints.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/src/amazon_echo/exceptions.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/src/amazon_echo/local.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/src/amazon_echo/models.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/src/amazon_echo/push.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/src/amazon_echo/py.typed +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/__init__.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/conftest.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/fixtures/automations.json +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/fixtures/devices.json +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/fixtures/graphql_endpoints.json +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/fixtures/graphql_smart_home.json +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/fixtures/history.json +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/fixtures/notifications.json +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/fixtures/np_player.json +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/test_auth.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/test_local.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/test_push.py +0 -0
- {python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/test_smart_home.py +0 -0
|
@@ -4,6 +4,22 @@ All notable changes to this project are documented here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.3.2] - 2026-11-16
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Music alarms had no time (`when` was `None`): Amazon sends `alarmTime: 0` for
|
|
12
|
+
them, so the time now comes from `originalDate` + `originalTime`. Found live.
|
|
13
|
+
|
|
14
|
+
## [0.3.1] - 2026-11-16
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- `create_timer` started the timer on the app's own registration instead of the
|
|
19
|
+
Echo (the app's timers API has no target device). It is now a typed request
|
|
20
|
+
with the duration in words, verified live in Portuguese; `locale` argument
|
|
21
|
+
added. Portuguese and English only.
|
|
22
|
+
|
|
7
23
|
## [0.3.0] - 2026-11-16
|
|
8
24
|
|
|
9
25
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: python-amazon-echo
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Async Python client for Amazon Echo / Alexa devices: state, settings, media, notifications, lists, HTTP/2 push and LAN discovery
|
|
5
5
|
Project-URL: Homepage, https://github.com/hudsonbrendon/python-amazon-echo
|
|
6
6
|
Project-URL: Repository, https://github.com/hudsonbrendon/python-amazon-echo
|
|
@@ -243,10 +243,10 @@ with mocked HTTP.
|
|
|
243
243
|
| `set_aux_direction` | no-op write accepted; the body field name is unconfirmed |
|
|
244
244
|
| `set_volume` (sequence pipeline) | no-op write |
|
|
245
245
|
| `create_reminder`, `delete_notification` | live (a reminder 320 days ahead was created and deleted) |
|
|
246
|
-
| `create_alarm` |
|
|
246
|
+
| `create_alarm` | verified live: a plain alarm earlier, and on 2026-11-16 a music alarm (`music=`, reusing a Spotify music alarm made by voice) created on an Echo Plus and deleted |
|
|
247
247
|
| `create_alarm(music=…)` (music alarm that reuses the station of an existing one) | ported from Alexa Media Player's request, never sent |
|
|
248
248
|
| `play_music(timer=…)` (stop after that many seconds) | ported from Alexa Media Player's payload, never sent |
|
|
249
|
-
| `create_timer` |
|
|
249
|
+
| `create_timer` | verified live on an Echo Plus (pt-BR): a 12-minute timer, with and without a name, created and deleted. It is a typed request with the duration in words; English phrases are unit-tested only |
|
|
250
250
|
| `set_wake_word` | ported |
|
|
251
251
|
| `speak`, `announce`, `text_command`, `play_sound`, `play_music`, `launch_skill`, `run_routine`, `stop` | ported |
|
|
252
252
|
| `media_command`, `bluetooth_connect`, `bluetooth_disconnect`, `reboot` | ported |
|
|
@@ -258,7 +258,7 @@ with mocked HTTP.
|
|
|
258
258
|
| `get_smart_home_endpoints` | live read; power, brightness, colour, colour temperature, temperature, battery, contact, motion and lock states and the operation names all parsed |
|
|
259
259
|
| `parse_endpoint_update` (smart-home push) | ported, not replayed live — no push stream on the test session |
|
|
260
260
|
| Smart-home operations through `call_feature` (`turnOn`, `turnOff`, `setBrightness`, `setColor`, `setColorTemperature`, `setMode`, `lock`, `unlock`) | ported, not replayed live — they change a device's visible state. The request shapes of `power`, `brightness`, `lock` and `toggle` are the ones in the Alexa app; the payload of `setColorTemperature` is inferred |
|
|
261
|
-
| `get_communication_preferences` | verified live once (an Echo Plus answered `announcements: true, communications: true, drop_in: all`); otherwise the service answered HTTP 503 on
|
|
261
|
+
| `get_communication_preferences` | verified live once (an Echo Plus answered `announcements: true, communications: true, drop_in: all`); otherwise the service answered HTTP 503 on roughly nine out of ten of some 60 requests on 2026-11-16, on both the `.com` and the marketplace host, with cookies or a bearer token |
|
|
262
262
|
| `set_communications`, `set_announcements`, `set_drop_in` | ported, not replayed live — the no-op write was attempted three times each and the service answered 503 every time |
|
|
263
263
|
| `get_device_preferences`, `get_kids_mode`, `get_children`, `get_kids_profile` | live read |
|
|
264
264
|
| `set_kids_mode` | ported, not replayed live — it changes how a device behaves |
|
|
@@ -294,8 +294,11 @@ with mocked HTTP.
|
|
|
294
294
|
- **Music alarms** can only reuse a station: `create_alarm(music=…)` takes a
|
|
295
295
|
music alarm that already exists on the account (create one in the Alexa app
|
|
296
296
|
first) and wakes with the same station. Amazon has no public search for one.
|
|
297
|
-
- **`create_timer
|
|
298
|
-
|
|
297
|
+
- **`create_timer`** speaks: Alexa has no API to start a timer on an Echo (the
|
|
298
|
+
app's timers API starts it on the app's own registration, which was observed
|
|
299
|
+
live), so the request is typed with the duration in words and Alexa confirms
|
|
300
|
+
it out loud. Portuguese and English only; other languages raise
|
|
301
|
+
`AmazonEchoNotSupportedError`.
|
|
299
302
|
- **Voice history** comes 10 records per call; at most 50 are fetched.
|
|
300
303
|
- **Lists** return the first 100 items.
|
|
301
304
|
- **`get_notifications`** is a large, rate-limited answer; call it sparingly (push
|
|
@@ -219,10 +219,10 @@ with mocked HTTP.
|
|
|
219
219
|
| `set_aux_direction` | no-op write accepted; the body field name is unconfirmed |
|
|
220
220
|
| `set_volume` (sequence pipeline) | no-op write |
|
|
221
221
|
| `create_reminder`, `delete_notification` | live (a reminder 320 days ahead was created and deleted) |
|
|
222
|
-
| `create_alarm` |
|
|
222
|
+
| `create_alarm` | verified live: a plain alarm earlier, and on 2026-11-16 a music alarm (`music=`, reusing a Spotify music alarm made by voice) created on an Echo Plus and deleted |
|
|
223
223
|
| `create_alarm(music=…)` (music alarm that reuses the station of an existing one) | ported from Alexa Media Player's request, never sent |
|
|
224
224
|
| `play_music(timer=…)` (stop after that many seconds) | ported from Alexa Media Player's payload, never sent |
|
|
225
|
-
| `create_timer` |
|
|
225
|
+
| `create_timer` | verified live on an Echo Plus (pt-BR): a 12-minute timer, with and without a name, created and deleted. It is a typed request with the duration in words; English phrases are unit-tested only |
|
|
226
226
|
| `set_wake_word` | ported |
|
|
227
227
|
| `speak`, `announce`, `text_command`, `play_sound`, `play_music`, `launch_skill`, `run_routine`, `stop` | ported |
|
|
228
228
|
| `media_command`, `bluetooth_connect`, `bluetooth_disconnect`, `reboot` | ported |
|
|
@@ -234,7 +234,7 @@ with mocked HTTP.
|
|
|
234
234
|
| `get_smart_home_endpoints` | live read; power, brightness, colour, colour temperature, temperature, battery, contact, motion and lock states and the operation names all parsed |
|
|
235
235
|
| `parse_endpoint_update` (smart-home push) | ported, not replayed live — no push stream on the test session |
|
|
236
236
|
| Smart-home operations through `call_feature` (`turnOn`, `turnOff`, `setBrightness`, `setColor`, `setColorTemperature`, `setMode`, `lock`, `unlock`) | ported, not replayed live — they change a device's visible state. The request shapes of `power`, `brightness`, `lock` and `toggle` are the ones in the Alexa app; the payload of `setColorTemperature` is inferred |
|
|
237
|
-
| `get_communication_preferences` | verified live once (an Echo Plus answered `announcements: true, communications: true, drop_in: all`); otherwise the service answered HTTP 503 on
|
|
237
|
+
| `get_communication_preferences` | verified live once (an Echo Plus answered `announcements: true, communications: true, drop_in: all`); otherwise the service answered HTTP 503 on roughly nine out of ten of some 60 requests on 2026-11-16, on both the `.com` and the marketplace host, with cookies or a bearer token |
|
|
238
238
|
| `set_communications`, `set_announcements`, `set_drop_in` | ported, not replayed live — the no-op write was attempted three times each and the service answered 503 every time |
|
|
239
239
|
| `get_device_preferences`, `get_kids_mode`, `get_children`, `get_kids_profile` | live read |
|
|
240
240
|
| `set_kids_mode` | ported, not replayed live — it changes how a device behaves |
|
|
@@ -270,8 +270,11 @@ with mocked HTTP.
|
|
|
270
270
|
- **Music alarms** can only reuse a station: `create_alarm(music=…)` takes a
|
|
271
271
|
music alarm that already exists on the account (create one in the Alexa app
|
|
272
272
|
first) and wakes with the same station. Amazon has no public search for one.
|
|
273
|
-
- **`create_timer
|
|
274
|
-
|
|
273
|
+
- **`create_timer`** speaks: Alexa has no API to start a timer on an Echo (the
|
|
274
|
+
app's timers API starts it on the app's own registration, which was observed
|
|
275
|
+
live), so the request is typed with the duration in words and Alexa confirms
|
|
276
|
+
it out loud. Portuguese and English only; other languages raise
|
|
277
|
+
`AmazonEchoNotSupportedError`.
|
|
275
278
|
- **Voice history** comes 10 records per call; at most 50 are fetched.
|
|
276
279
|
- **Lists** return the first 100 items.
|
|
277
280
|
- **`get_notifications`** is a large, rate-limited answer; call it sparingly (push
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "python-amazon-echo"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.2"
|
|
8
8
|
description = "Async Python client for Amazon Echo / Alexa devices: state, settings, media, notifications, lists, HTTP/2 push and LAN discovery"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -67,11 +67,14 @@ from .models import (
|
|
|
67
67
|
Routine,
|
|
68
68
|
VoiceRecord,
|
|
69
69
|
)
|
|
70
|
+
from .phrases import timer_request
|
|
70
71
|
|
|
71
72
|
_LOGGER = logging.getLogger(__name__)
|
|
72
73
|
|
|
73
74
|
_TIMEOUT = aiohttp.ClientTimeout(total=30)
|
|
74
75
|
_RETRY_DELAYS = (1.0, 3.0) # back-off before the 2nd and 3rd attempt on 429/503
|
|
76
|
+
_TIMER_POLLS = 8
|
|
77
|
+
_TIMER_POLL_SECONDS = 3.0
|
|
75
78
|
_REAUTH_COOLDOWN = 60.0 # a 401/403 this soon after a cookie exchange is final
|
|
76
79
|
_TOKEN_MARGIN = 60.0
|
|
77
80
|
_HISTORY_CSRF_TTL = 12 * 3600
|
|
@@ -124,6 +127,26 @@ def _local(when: datetime) -> datetime:
|
|
|
124
127
|
return when.astimezone().replace(tzinfo=None) if when.tzinfo else when
|
|
125
128
|
|
|
126
129
|
|
|
130
|
+
def _from_original(item: dict[str, Any]) -> datetime | None:
|
|
131
|
+
"""Local ``originalDate`` + ``originalTime`` (music alarms carry only these).
|
|
132
|
+
|
|
133
|
+
Same time zone assumption as :func:`_local`; a repeating alarm whose first
|
|
134
|
+
date is past moves to its next ring.
|
|
135
|
+
"""
|
|
136
|
+
date, clock = item.get("originalDate"), item.get("originalTime")
|
|
137
|
+
if not date or not clock:
|
|
138
|
+
return None
|
|
139
|
+
try:
|
|
140
|
+
when = datetime.fromisoformat(f"{date}T{str(clock)[:8]}").astimezone()
|
|
141
|
+
if item.get("recurringPattern") and when < datetime.now().astimezone():
|
|
142
|
+
# _next_ring works on local wall-clock time
|
|
143
|
+
ring = _next_ring(item, datetime.now()) # noqa: DTZ005
|
|
144
|
+
when = datetime.fromisoformat(ring).astimezone()
|
|
145
|
+
except ValueError:
|
|
146
|
+
return None
|
|
147
|
+
return when
|
|
148
|
+
|
|
149
|
+
|
|
127
150
|
def parse_notification(item: dict[str, Any]) -> Notification:
|
|
128
151
|
"""Build a :class:`Notification` from an ``/api/notifications`` item."""
|
|
129
152
|
kind = NOTIFICATION_KINDS.get(item.get("type") or "", "")
|
|
@@ -131,7 +154,11 @@ def parse_notification(item: dict[str, Any]) -> Notification:
|
|
|
131
154
|
if item.get("musicAlarmId") and kind == "alarm":
|
|
132
155
|
kind = "music_alarm"
|
|
133
156
|
remaining = item.get("remainingTime") or 0
|
|
134
|
-
when =
|
|
157
|
+
when = (
|
|
158
|
+
_from_ms(item.get("triggerTime"))
|
|
159
|
+
or _from_ms(item.get("alarmTime"))
|
|
160
|
+
or (_from_original(item) if kind in ("alarm", "music_alarm") else None)
|
|
161
|
+
)
|
|
135
162
|
return Notification(
|
|
136
163
|
id=item["id"],
|
|
137
164
|
kind=kind,
|
|
@@ -1676,30 +1703,45 @@ class AmazonEchoClient:
|
|
|
1676
1703
|
raise AmazonEchoResponseError(200, "No reminder in the answer")
|
|
1677
1704
|
|
|
1678
1705
|
async def create_timer(
|
|
1679
|
-
self,
|
|
1706
|
+
self,
|
|
1707
|
+
device: Device,
|
|
1708
|
+
duration: timedelta,
|
|
1709
|
+
*,
|
|
1710
|
+
label: str | None = None,
|
|
1711
|
+
locale: str | None = None,
|
|
1680
1712
|
) -> Notification:
|
|
1681
|
-
"""Start a timer on ``device
|
|
1713
|
+
"""Start a timer on ``device``; Alexa confirms it out loud.
|
|
1714
|
+
|
|
1715
|
+
Amazon has no API for this: the timers API of the app starts the timer
|
|
1716
|
+
on the app's own registration, not on an Echo. What works is a typed
|
|
1717
|
+
request with the duration in words (see :mod:`amazon_echo.phrases`),
|
|
1718
|
+
available for Portuguese and English.
|
|
1719
|
+
|
|
1720
|
+
Args:
|
|
1721
|
+
device: The Echo that will run the timer.
|
|
1722
|
+
duration: More than zero and less than 24 hours.
|
|
1723
|
+
label: Optional name of the timer.
|
|
1724
|
+
locale: Locale of the device; read from Amazon when omitted.
|
|
1725
|
+
|
|
1726
|
+
Raises:
|
|
1727
|
+
AmazonEchoNotSupportedError: No phrase for the device's language.
|
|
1728
|
+
AmazonEchoResponseError: Alexa did not start the timer.
|
|
1729
|
+
ValueError: The duration is out of range.
|
|
1682
1730
|
|
|
1683
|
-
The request body follows the field names found in the Alexa app
|
|
1684
|
-
(``/v1/alerts/timers``); it has not been replayed against Amazon.
|
|
1685
1731
|
"""
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1732
|
+
if locale is None:
|
|
1733
|
+
preferences = await self.get_device_preferences()
|
|
1734
|
+
locale = (preferences.get(device.serial) or {}).get("locale") or "en-US"
|
|
1735
|
+
request = timer_request(duration, locale, label=label)
|
|
1689
1736
|
known = {item.id for item in await self.get_notifications()}
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
}
|
|
1699
|
-
if label:
|
|
1700
|
-
body["timerLabel"] = label
|
|
1701
|
-
await self._alerts("POST", "timers", body)
|
|
1702
|
-
return await self._find_new(device, "timer", known)
|
|
1737
|
+
await self.text_command(device, request)
|
|
1738
|
+
for _ in range(_TIMER_POLLS):
|
|
1739
|
+
await asyncio.sleep(_TIMER_POLL_SECONDS)
|
|
1740
|
+
try:
|
|
1741
|
+
return await self._find_new(device, "timer", known)
|
|
1742
|
+
except AmazonEchoResponseError:
|
|
1743
|
+
continue
|
|
1744
|
+
raise AmazonEchoResponseError(200, "The new timer did not show up")
|
|
1703
1745
|
|
|
1704
1746
|
@staticmethod
|
|
1705
1747
|
def _alarm_index(alarm: Notification) -> str:
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Spoken phrases for the things Alexa only accepts as a voice request.
|
|
2
|
+
|
|
3
|
+
Alexa has no API to start a timer on an Echo: the timers API of the app starts
|
|
4
|
+
it on the app's own registration. A typed request works, but only with the
|
|
5
|
+
numbers spelled out ("timer de dez minutos" starts one, "timer de 10 minutos"
|
|
6
|
+
makes Alexa ask for how long), so the duration is written in words here.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from datetime import timedelta
|
|
12
|
+
|
|
13
|
+
from .exceptions import AmazonEchoNotSupportedError
|
|
14
|
+
|
|
15
|
+
_PT_UNITS = [
|
|
16
|
+
"zero",
|
|
17
|
+
"um",
|
|
18
|
+
"dois",
|
|
19
|
+
"três",
|
|
20
|
+
"quatro",
|
|
21
|
+
"cinco",
|
|
22
|
+
"seis",
|
|
23
|
+
"sete",
|
|
24
|
+
"oito",
|
|
25
|
+
"nove",
|
|
26
|
+
"dez",
|
|
27
|
+
"onze",
|
|
28
|
+
"doze",
|
|
29
|
+
"treze",
|
|
30
|
+
"quatorze",
|
|
31
|
+
"quinze",
|
|
32
|
+
"dezesseis",
|
|
33
|
+
"dezessete",
|
|
34
|
+
"dezoito",
|
|
35
|
+
"dezenove",
|
|
36
|
+
]
|
|
37
|
+
_PT_TENS = {20: "vinte", 30: "trinta", 40: "quarenta", 50: "cinquenta"}
|
|
38
|
+
_EN_UNITS = [
|
|
39
|
+
"zero",
|
|
40
|
+
"one",
|
|
41
|
+
"two",
|
|
42
|
+
"three",
|
|
43
|
+
"four",
|
|
44
|
+
"five",
|
|
45
|
+
"six",
|
|
46
|
+
"seven",
|
|
47
|
+
"eight",
|
|
48
|
+
"nine",
|
|
49
|
+
"ten",
|
|
50
|
+
"eleven",
|
|
51
|
+
"twelve",
|
|
52
|
+
"thirteen",
|
|
53
|
+
"fourteen",
|
|
54
|
+
"fifteen",
|
|
55
|
+
"sixteen",
|
|
56
|
+
"seventeen",
|
|
57
|
+
"eighteen",
|
|
58
|
+
"nineteen",
|
|
59
|
+
]
|
|
60
|
+
_EN_TENS = {20: "twenty", 30: "thirty", 40: "forty", 50: "fifty"}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _pt(number: int, *, feminine: bool = False) -> str:
|
|
64
|
+
if number < 20:
|
|
65
|
+
word = _PT_UNITS[number]
|
|
66
|
+
return {"um": "uma", "dois": "duas"}.get(word, word) if feminine else word
|
|
67
|
+
tens, rest = number - number % 10, number % 10
|
|
68
|
+
return _PT_TENS[tens] + (f" e {_pt(rest, feminine=feminine)}" if rest else "")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _en(number: int) -> str:
|
|
72
|
+
if number < 20:
|
|
73
|
+
return _EN_UNITS[number]
|
|
74
|
+
tens, rest = number - number % 10, number % 10
|
|
75
|
+
return _EN_TENS[tens] + (f"-{_EN_UNITS[rest]}" if rest else "")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _parts(duration: timedelta) -> tuple[int, int, int]:
|
|
79
|
+
seconds = int(duration.total_seconds())
|
|
80
|
+
if not 0 < seconds < 24 * 3600:
|
|
81
|
+
raise ValueError("The timer duration must be between 1 second and 24 hours")
|
|
82
|
+
return seconds // 3600, seconds % 3600 // 60, seconds % 60
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def timer_request(
|
|
86
|
+
duration: timedelta, language: str, *, label: str | None = None
|
|
87
|
+
) -> str:
|
|
88
|
+
"""Return the typed request that starts a timer of ``duration``.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
duration: More than zero and less than 24 hours.
|
|
92
|
+
language: Locale of the device, e.g. ``pt-BR`` or ``en-US``.
|
|
93
|
+
label: Optional name of the timer.
|
|
94
|
+
|
|
95
|
+
Raises:
|
|
96
|
+
AmazonEchoNotSupportedError: No phrase for that language.
|
|
97
|
+
ValueError: The duration is out of range.
|
|
98
|
+
|
|
99
|
+
"""
|
|
100
|
+
hours, minutes, seconds = _parts(duration)
|
|
101
|
+
code = language[:2].lower()
|
|
102
|
+
if code == "pt":
|
|
103
|
+
spoken = " e ".join(
|
|
104
|
+
f"{_pt(n, feminine=feminine)} {one if n == 1 else many}"
|
|
105
|
+
for n, one, many, feminine in (
|
|
106
|
+
(hours, "hora", "horas", True),
|
|
107
|
+
(minutes, "minuto", "minutos", False),
|
|
108
|
+
(seconds, "segundo", "segundos", False),
|
|
109
|
+
)
|
|
110
|
+
if n
|
|
111
|
+
)
|
|
112
|
+
return f"timer de {spoken}" + (f" chamado {label}" if label else "")
|
|
113
|
+
if code == "en":
|
|
114
|
+
spoken = " and ".join(
|
|
115
|
+
f"{_en(n)} {one if n == 1 else many}"
|
|
116
|
+
for n, one, many in (
|
|
117
|
+
(hours, "hour", "hours"),
|
|
118
|
+
(minutes, "minute", "minutes"),
|
|
119
|
+
(seconds, "second", "seconds"),
|
|
120
|
+
)
|
|
121
|
+
if n
|
|
122
|
+
)
|
|
123
|
+
return (
|
|
124
|
+
(f"set a {label} timer for {spoken}")
|
|
125
|
+
if label
|
|
126
|
+
else f"set a timer for {spoken}"
|
|
127
|
+
)
|
|
128
|
+
raise AmazonEchoNotSupportedError(f"No timer phrase for the language {language!r}")
|
|
@@ -22,6 +22,7 @@ from amazon_echo import (
|
|
|
22
22
|
Routine,
|
|
23
23
|
)
|
|
24
24
|
from amazon_echo.client import _recurrence_rule, format_mac, parse_notification
|
|
25
|
+
from amazon_echo.phrases import timer_request
|
|
25
26
|
|
|
26
27
|
from .conftest import FakeResponse, load_json
|
|
27
28
|
|
|
@@ -1300,7 +1301,8 @@ async def test_alerts_api_missing(client, session, office):
|
|
|
1300
1301
|
await client.create_alarm(office, datetime(2027, 1, 15, 7, 0))
|
|
1301
1302
|
|
|
1302
1303
|
|
|
1303
|
-
async def test_create_timer(client, session, office):
|
|
1304
|
+
async def test_create_timer(client, session, office, monkeypatch):
|
|
1305
|
+
monkeypatch.setattr("amazon_echo.client._TIMER_POLL_SECONDS", 0)
|
|
1304
1306
|
new = {
|
|
1305
1307
|
"id": "A18O6U1UQFJ0XK-G000TEST00000001-timer",
|
|
1306
1308
|
"type": "Timer",
|
|
@@ -1310,17 +1312,59 @@ async def test_create_timer(client, session, office):
|
|
|
1310
1312
|
"remainingTime": 300_000,
|
|
1311
1313
|
"createdDate": 1_800_000_000_000,
|
|
1312
1314
|
}
|
|
1313
|
-
|
|
1314
|
-
session.add("GET", "/api/
|
|
1315
|
-
session.add("POST", "/
|
|
1316
|
-
timer = await client.create_timer(
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
assert
|
|
1315
|
+
# before, first poll (not there yet), second poll
|
|
1316
|
+
session.add("GET", "/api/notifications", _listing(), _listing(), _listing(new))
|
|
1317
|
+
session.add("POST", "/api/behaviors/preview", None)
|
|
1318
|
+
timer = await client.create_timer(
|
|
1319
|
+
office, timedelta(minutes=5), label="tea", locale="en-US"
|
|
1320
|
+
)
|
|
1321
|
+
node = node_of(session)
|
|
1322
|
+
assert node["type"] == "Alexa.TextCommand"
|
|
1323
|
+
assert node["operationPayload"]["text"] == "set a tea timer for five minutes"
|
|
1321
1324
|
assert timer.remaining == timedelta(minutes=5)
|
|
1322
|
-
with pytest.raises(ValueError, match="
|
|
1323
|
-
await client.create_timer(office, timedelta(0))
|
|
1325
|
+
with pytest.raises(ValueError, match="between"):
|
|
1326
|
+
await client.create_timer(office, timedelta(0), locale="en-US")
|
|
1327
|
+
with pytest.raises(AmazonEchoNotSupportedError):
|
|
1328
|
+
await client.create_timer(office, timedelta(minutes=1), locale="ja-JP")
|
|
1329
|
+
|
|
1330
|
+
|
|
1331
|
+
async def test_create_timer_never_shows_up(client, session, office, monkeypatch):
|
|
1332
|
+
monkeypatch.setattr("amazon_echo.client._TIMER_POLL_SECONDS", 0)
|
|
1333
|
+
monkeypatch.setattr("amazon_echo.client._TIMER_POLLS", 2)
|
|
1334
|
+
session.add("GET", "/api/notifications", _listing())
|
|
1335
|
+
session.add("POST", "/api/behaviors/preview", None)
|
|
1336
|
+
with pytest.raises(AmazonEchoResponseError, match="did not show up"):
|
|
1337
|
+
await client.create_timer(office, timedelta(minutes=5), locale="pt-BR")
|
|
1338
|
+
|
|
1339
|
+
|
|
1340
|
+
@pytest.mark.parametrize(
|
|
1341
|
+
("duration", "language", "label", "expected"),
|
|
1342
|
+
[
|
|
1343
|
+
(timedelta(minutes=10), "pt-BR", None, "timer de dez minutos"),
|
|
1344
|
+
(timedelta(hours=1), "pt-BR", None, "timer de uma hora"),
|
|
1345
|
+
(
|
|
1346
|
+
timedelta(hours=2, minutes=21, seconds=1),
|
|
1347
|
+
"pt-BR",
|
|
1348
|
+
None,
|
|
1349
|
+
"timer de duas horas e vinte e um minutos e um segundo",
|
|
1350
|
+
),
|
|
1351
|
+
(
|
|
1352
|
+
timedelta(minutes=12),
|
|
1353
|
+
"pt-BR",
|
|
1354
|
+
"pizza",
|
|
1355
|
+
"timer de doze minutos chamado pizza",
|
|
1356
|
+
),
|
|
1357
|
+
(timedelta(minutes=45), "en-US", None, "set a timer for forty-five minutes"),
|
|
1358
|
+
(
|
|
1359
|
+
timedelta(hours=1, seconds=30),
|
|
1360
|
+
"en-GB",
|
|
1361
|
+
None,
|
|
1362
|
+
"set a timer for one hour and thirty seconds",
|
|
1363
|
+
),
|
|
1364
|
+
],
|
|
1365
|
+
)
|
|
1366
|
+
def test_timer_request(duration, language, label, expected):
|
|
1367
|
+
assert timer_request(duration, language, label=label) == expected
|
|
1324
1368
|
|
|
1325
1369
|
|
|
1326
1370
|
async def test_delete_notification(client, session):
|
|
@@ -1597,3 +1641,29 @@ async def test_cookie_refresh_works_right_after_boot(client, session, monkeypatc
|
|
|
1597
1641
|
session.add("POST", "/auth/token", COOKIE_ANSWER)
|
|
1598
1642
|
assert await client.request("GET", "/api/x") == {"ok": 1}
|
|
1599
1643
|
assert len(session.sent("/auth/token")) == 1
|
|
1644
|
+
|
|
1645
|
+
|
|
1646
|
+
def test_music_alarm_time_comes_from_the_original_fields():
|
|
1647
|
+
item = {
|
|
1648
|
+
"id": "A18O6U1UQFJ0XK-G000TEST00000001-music",
|
|
1649
|
+
"type": "MusicAlarm",
|
|
1650
|
+
"status": "ON",
|
|
1651
|
+
"deviceSerialNumber": "G000TEST00000001",
|
|
1652
|
+
"deviceType": "A18O6U1UQFJ0XK",
|
|
1653
|
+
"alarmTime": 0,
|
|
1654
|
+
"triggerTime": 0,
|
|
1655
|
+
"originalDate": "2030-12-06",
|
|
1656
|
+
"originalTime": "06:10:00.000",
|
|
1657
|
+
"musicAlarmId": "fake-music-alarm",
|
|
1658
|
+
"provider": "Spotify",
|
|
1659
|
+
"musicEntity": "fake station",
|
|
1660
|
+
}
|
|
1661
|
+
alarm = parse_notification(item)
|
|
1662
|
+
assert alarm.kind == "music_alarm"
|
|
1663
|
+
assert alarm.when == datetime(2030, 12, 6, 6, 10).astimezone()
|
|
1664
|
+
assert parse_notification({**item, "originalDate": None}).when is None
|
|
1665
|
+
repeating = parse_notification(
|
|
1666
|
+
{**item, "originalDate": "2020-01-01", "recurringPattern": "P1D"}
|
|
1667
|
+
)
|
|
1668
|
+
assert repeating.when is not None
|
|
1669
|
+
assert repeating.when > datetime.now().astimezone()
|
|
@@ -7,7 +7,7 @@ from amazon_echo import Device, Notification, PushEvent
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
def test_public_api():
|
|
10
|
-
assert amazon_echo.__version__ == "0.3.
|
|
10
|
+
assert amazon_echo.__version__ == "0.3.2"
|
|
11
11
|
for name in amazon_echo.__all__:
|
|
12
12
|
assert hasattr(amazon_echo, name)
|
|
13
13
|
assert issubclass(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_amazon_echo-0.3.0 → python_amazon_echo-0.3.2}/tests/fixtures/graphql_smart_home.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|