python-amazon-echo 0.3.1__tar.gz → 0.3.3__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.
Files changed (33) hide show
  1. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/CHANGELOG.md +15 -0
  2. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/PKG-INFO +5 -5
  3. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/README.md +4 -4
  4. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/pyproject.toml +1 -1
  5. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/__init__.py +1 -1
  6. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/client.py +55 -2
  7. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/const.py +1 -1
  8. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/test_client.py +65 -0
  9. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/test_models.py +1 -1
  10. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/.gitignore +0 -0
  11. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/LICENSE +0 -0
  12. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/__main__.py +0 -0
  13. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/auth.py +0 -0
  14. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/endpoints.py +0 -0
  15. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/exceptions.py +0 -0
  16. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/local.py +0 -0
  17. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/models.py +0 -0
  18. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/phrases.py +0 -0
  19. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/push.py +0 -0
  20. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/src/amazon_echo/py.typed +0 -0
  21. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/__init__.py +0 -0
  22. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/conftest.py +0 -0
  23. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/fixtures/automations.json +0 -0
  24. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/fixtures/devices.json +0 -0
  25. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/fixtures/graphql_endpoints.json +0 -0
  26. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/fixtures/graphql_smart_home.json +0 -0
  27. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/fixtures/history.json +0 -0
  28. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/fixtures/notifications.json +0 -0
  29. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/fixtures/np_player.json +0 -0
  30. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/test_auth.py +0 -0
  31. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/test_local.py +0 -0
  32. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/test_push.py +0 -0
  33. {python_amazon_echo-0.3.1 → python_amazon_echo-0.3.3}/tests/test_smart_home.py +0 -0
@@ -4,6 +4,21 @@ 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.3] - 2026-11-16
8
+
9
+ ### Fixed
10
+
11
+ - `get_media` reported Spotify (and other external players) as idle:
12
+ `/api/np/player` stays empty for them, so it now falls back to
13
+ `/api/np/list-media-sessions`. Found and verified live.
14
+
15
+ ## [0.3.2] - 2026-11-16
16
+
17
+ ### Fixed
18
+
19
+ - Music alarms had no time (`when` was `None`): Amazon sends `alarmTime: 0` for
20
+ them, so the time now comes from `originalDate` + `originalTime`. Found live.
21
+
7
22
  ## [0.3.1] - 2026-11-16
8
23
 
9
24
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: python-amazon-echo
3
- Version: 0.3.1
3
+ Version: 0.3.3
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
@@ -235,7 +235,7 @@ with mocked HTTP.
235
235
  | `build_authorize_url`, `register_device` | ported (the authorize URL answers 302 as expected; no registration was made) |
236
236
  | `get_account`, `get_devices`, `get_routines`, `get_music_providers`, `get_service_urls` | live read |
237
237
  | `get_dnd`, `get_volumes`, `get_bluetooth`, `get_notifications`, `get_alarm_volumes`, `get_wake_words`, `get_ascending_alarms`, `get_endpoint_states` | live read |
238
- | `get_media` | live read (idle player only) |
238
+ | `get_media` | verified live on 2026-11-16 with Spotify: playing, title, provider and position, then paused when the sleep timer ran out |
239
239
  | `get_wifi`, `get_equalizer`, `get_earcons`, `get_aux`, `get_setting`, `get_available_wake_words`, `get_alarm_sounds`, `get_default_alarm_sound` | live read |
240
240
  | `get_whisper_mode`, `get_adaptive_volume` | live read |
241
241
  | `set_whisper_mode`, `set_adaptive_volume` | no-op write during the reverse engineering (same request), not replayed by the library |
@@ -243,7 +243,7 @@ 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` | ported |
246
+ | `create_alarm` | music alarm verified live on 2026-11-16 (`music=`, reusing a Spotify music alarm made by voice): created on an Echo Plus with the requested date and time, then deleted. A plain alarm is ported, not replayed live |
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
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 |
@@ -258,8 +258,8 @@ 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 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
- | `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 |
261
+ | `get_communication_preferences` | verified live on an Echo Plus. The service is flaky for this account: on 2026-11-16 it answered HTTP 503 to roughly nine requests out of ten, on both the `.com` and the marketplace host |
262
+ | `set_communications`, `set_announcements`, `set_drop_in` | verified live on 2026-11-16 with no-op writes (the value just read) on an Echo Plus, read back unchanged; each took up to six attempts because of the 503s above |
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 |
265
265
  | `get_guard` | live for an account without Guard (the appliance list is read, no panel is found, None); the state read is ported — the test account has no Guard |
@@ -211,7 +211,7 @@ with mocked HTTP.
211
211
  | `build_authorize_url`, `register_device` | ported (the authorize URL answers 302 as expected; no registration was made) |
212
212
  | `get_account`, `get_devices`, `get_routines`, `get_music_providers`, `get_service_urls` | live read |
213
213
  | `get_dnd`, `get_volumes`, `get_bluetooth`, `get_notifications`, `get_alarm_volumes`, `get_wake_words`, `get_ascending_alarms`, `get_endpoint_states` | live read |
214
- | `get_media` | live read (idle player only) |
214
+ | `get_media` | verified live on 2026-11-16 with Spotify: playing, title, provider and position, then paused when the sleep timer ran out |
215
215
  | `get_wifi`, `get_equalizer`, `get_earcons`, `get_aux`, `get_setting`, `get_available_wake_words`, `get_alarm_sounds`, `get_default_alarm_sound` | live read |
216
216
  | `get_whisper_mode`, `get_adaptive_volume` | live read |
217
217
  | `set_whisper_mode`, `set_adaptive_volume` | no-op write during the reverse engineering (same request), not replayed by the library |
@@ -219,7 +219,7 @@ 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` | ported |
222
+ | `create_alarm` | music alarm verified live on 2026-11-16 (`music=`, reusing a Spotify music alarm made by voice): created on an Echo Plus with the requested date and time, then deleted. A plain alarm is ported, not replayed live |
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
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 |
@@ -234,8 +234,8 @@ 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 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
- | `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 |
237
+ | `get_communication_preferences` | verified live on an Echo Plus. The service is flaky for this account: on 2026-11-16 it answered HTTP 503 to roughly nine requests out of ten, on both the `.com` and the marketplace host |
238
+ | `set_communications`, `set_announcements`, `set_drop_in` | verified live on 2026-11-16 with no-op writes (the value just read) on an Echo Plus, read back unchanged; each took up to six attempts because of the 503s above |
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 |
241
241
  | `get_guard` | live for an account without Guard (the appliance list is read, no panel is found, None); the state read is ported — the test account has no Guard |
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "python-amazon-echo"
7
- version = "0.3.1"
7
+ version = "0.3.3"
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"
@@ -30,7 +30,7 @@ from .models import (
30
30
  )
31
31
  from .push import PushClient, PushEvent
32
32
 
33
- __version__ = "0.3.1"
33
+ __version__ = "0.3.3"
34
34
 
35
35
  __all__ = [
36
36
  "Account",
@@ -127,6 +127,26 @@ def _local(when: datetime) -> datetime:
127
127
  return when.astimezone().replace(tzinfo=None) if when.tzinfo else when
128
128
 
129
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
+
130
150
  def parse_notification(item: dict[str, Any]) -> Notification:
131
151
  """Build a :class:`Notification` from an ``/api/notifications`` item."""
132
152
  kind = NOTIFICATION_KINDS.get(item.get("type") or "", "")
@@ -134,7 +154,11 @@ def parse_notification(item: dict[str, Any]) -> Notification:
134
154
  if item.get("musicAlarmId") and kind == "alarm":
135
155
  kind = "music_alarm"
136
156
  remaining = item.get("remainingTime") or 0
137
- when = _from_ms(item.get("triggerTime")) or _from_ms(item.get("alarmTime"))
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
+ )
138
162
  return Notification(
139
163
  id=item["id"],
140
164
  kind=kind,
@@ -154,6 +178,20 @@ def parse_notification(item: dict[str, Any]) -> Notification:
154
178
  )
155
179
 
156
180
 
181
+ def _session_as_player(now: dict[str, Any]) -> dict[str, Any]:
182
+ """Shape a media session's ``nowPlayingData`` like ``playerInfo``.
183
+
184
+ The session names the state ``playerState`` and counts in milliseconds.
185
+ """
186
+ progress = dict(now.get("progress") or {})
187
+ for key in ("mediaLength", "mediaProgress"):
188
+ try:
189
+ progress[key] = float(progress[key]) / 1000
190
+ except KeyError, TypeError, ValueError:
191
+ progress.pop(key, None)
192
+ return {**now, "state": now.get("playerState"), "progress": progress}
193
+
194
+
157
195
  def _parse_media(info: dict[str, Any]) -> MediaState:
158
196
  """Build a :class:`MediaState` from the ``playerInfo`` of ``/api/np/player``."""
159
197
  transport = info.get("transport") or {}
@@ -768,7 +806,22 @@ class AmazonEchoClient:
768
806
  "/api/np/player",
769
807
  params={**self._query(device), "screenWidth": "2560"},
770
808
  )
771
- return _parse_media((data or {}).get("playerInfo") or {})
809
+ info = (data or {}).get("playerInfo") or {}
810
+ if info.get("state"):
811
+ return _parse_media(info)
812
+ # Spotify and other external players leave /api/np/player empty and
813
+ # only show up as a media session (observed live).
814
+ try:
815
+ sessions = await self._request(
816
+ "GET", "/api/np/list-media-sessions", params=self._query(device)
817
+ )
818
+ except AmazonEchoResponseError:
819
+ return _parse_media(info)
820
+ for session in (sessions or {}).get("mediaSessionList") or []:
821
+ now = session.get("nowPlayingData") or {}
822
+ if now.get("playerState"):
823
+ return _parse_media(_session_as_player(now))
824
+ return _parse_media(info)
772
825
 
773
826
  async def get_endpoint_states(self) -> dict[str, dict[str, Any]]:
774
827
  """Return the GraphQL state of every Alexa endpoint by device serial.
@@ -4,7 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  from typing import Any, Final
6
6
 
7
- VERSION: Final = "0.3.1"
7
+ VERSION: Final = "0.3.3"
8
8
 
9
9
  # Identity of the Alexa iOS app, which is what a registration impersonates.
10
10
  APP_NAME: Final = "Amazon Echo for Home Assistant"
@@ -662,6 +662,7 @@ async def test_get_media_idle(client, session, office):
662
662
  session.add(
663
663
  "GET", "/api/np/player", {"playerInfo": {"state": None, "volume": None}}
664
664
  )
665
+ session.add("GET", "/api/np/list-media-sessions", {"mediaSessionList": []})
665
666
  media = await client.get_media(office)
666
667
  assert media.state == "idle"
667
668
  assert media.title is None
@@ -1641,3 +1642,67 @@ async def test_cookie_refresh_works_right_after_boot(client, session, monkeypatc
1641
1642
  session.add("POST", "/auth/token", COOKIE_ANSWER)
1642
1643
  assert await client.request("GET", "/api/x") == {"ok": 1}
1643
1644
  assert len(session.sent("/auth/token")) == 1
1645
+
1646
+
1647
+ def test_music_alarm_time_comes_from_the_original_fields():
1648
+ item = {
1649
+ "id": "A18O6U1UQFJ0XK-G000TEST00000001-music",
1650
+ "type": "MusicAlarm",
1651
+ "status": "ON",
1652
+ "deviceSerialNumber": "G000TEST00000001",
1653
+ "deviceType": "A18O6U1UQFJ0XK",
1654
+ "alarmTime": 0,
1655
+ "triggerTime": 0,
1656
+ "originalDate": "2030-12-06",
1657
+ "originalTime": "06:10:00.000",
1658
+ "musicAlarmId": "fake-music-alarm",
1659
+ "provider": "Spotify",
1660
+ "musicEntity": "fake station",
1661
+ }
1662
+ alarm = parse_notification(item)
1663
+ assert alarm.kind == "music_alarm"
1664
+ assert alarm.when == datetime(2030, 12, 6, 6, 10).astimezone()
1665
+ assert parse_notification({**item, "originalDate": None}).when is None
1666
+ repeating = parse_notification(
1667
+ {**item, "originalDate": "2020-01-01", "recurringPattern": "P1D"}
1668
+ )
1669
+ assert repeating.when is not None
1670
+ assert repeating.when > datetime.now().astimezone()
1671
+
1672
+
1673
+ async def test_get_media_falls_back_to_media_sessions(client, session, office):
1674
+ session.add("GET", "/api/np/player", {"playerInfo": {"state": None}})
1675
+ session.add(
1676
+ "GET",
1677
+ "/api/np/list-media-sessions",
1678
+ {
1679
+ "mediaSessionList": [
1680
+ {
1681
+ "nowPlayingData": {
1682
+ "playerState": "PLAYING",
1683
+ "infoText": {"title": "Song", "subText1": "Band"},
1684
+ "progress": {
1685
+ "mediaLength": 290110,
1686
+ "mediaProgress": 26420,
1687
+ "allowScrubbing": True,
1688
+ },
1689
+ "provider": {"providerName": "Spotify"},
1690
+ "transport": {"next": "ENABLED", "shuffle": "SELECTED"},
1691
+ }
1692
+ }
1693
+ ]
1694
+ },
1695
+ )
1696
+ media = await client.get_media(office)
1697
+ assert media.state == "playing"
1698
+ assert (media.title, media.artist, media.provider) == ("Song", "Band", "Spotify")
1699
+ assert media.duration == pytest.approx(290.11)
1700
+ assert media.position == pytest.approx(26.42)
1701
+ assert media.shuffle is True
1702
+ assert media.can_next is True
1703
+
1704
+
1705
+ async def test_get_media_idle_without_sessions(client, session, office):
1706
+ session.add("GET", "/api/np/player", {"playerInfo": {}})
1707
+ session.add("GET", "/api/np/list-media-sessions", {"mediaSessionList": []})
1708
+ assert (await client.get_media(office)).state == "idle"
@@ -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.1"
10
+ assert amazon_echo.__version__ == "0.3.3"
11
11
  for name in amazon_echo.__all__:
12
12
  assert hasattr(amazon_echo, name)
13
13
  assert issubclass(