python-amazon-echo 0.3.1__py3-none-any.whl → 0.3.3__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.
amazon_echo/__init__.py CHANGED
@@ -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",
amazon_echo/client.py CHANGED
@@ -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.
amazon_echo/const.py CHANGED
@@ -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"
@@ -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 |
@@ -1,8 +1,8 @@
1
- amazon_echo/__init__.py,sha256=A2TR67ga1Q9cB1wzlf8PWPzoIHxSfiu5F4nsgJ9RAMU,1437
1
+ amazon_echo/__init__.py,sha256=8JAFK4beijtBp-7H4LwRS7QGkYcc_eQNxy-vq-BcvWY,1437
2
2
  amazon_echo/__main__.py,sha256=1Hhd7w2cW5Z9jmwO1OThhcj6gbTLVqAQu5fAMqijJ_0,4325
3
3
  amazon_echo/auth.py,sha256=O5SAtY5Wf76-LtFOkHJvrzlNoZdprgJsx5-3crEPUGQ,14417
4
- amazon_echo/client.py,sha256=CwzLzZn8zNO2pHp7FpYpUCrXw73e37vCcM6Sq9uRBE4,81267
5
- amazon_echo/const.py,sha256=VdwrTHytFm4Yh-qlcClfTFL-KnnfyClWGA-7W_sU2X4,11880
4
+ amazon_echo/client.py,sha256=_IHh8dAEm75c7S6zMPzJDjglCuLsEkIl3KRiFdwZ_QM,83398
5
+ amazon_echo/const.py,sha256=NGzHwwkeU7ILwhG-Vi4_fEmDTe1abiY_cyqraguiZy0,11880
6
6
  amazon_echo/endpoints.py,sha256=_6vXYWtwGIR_2IjVFJAXWP1vR6jwzIpZ4upkRctwBp8,7925
7
7
  amazon_echo/exceptions.py,sha256=7ETH4C2sKbKEJWnJ30ygAO0a_GiD5PWmDHJCSVTedAU,1120
8
8
  amazon_echo/local.py,sha256=KHwwgC2-MzFZ0wBaxXRuotyr7-zrrenzfM0P3BEMRvE,3080
@@ -10,8 +10,8 @@ amazon_echo/models.py,sha256=ZKEHuiyG7hqRt5M8nufyf1nyaRZ2-l1WXlOCzG4UH7A,5258
10
10
  amazon_echo/phrases.py,sha256=iqhqIK07XRTWmAwJ5jhzGPtqatvUz4nywCvJvCgwTK0,3579
11
11
  amazon_echo/push.py,sha256=KMcHeDLgRxEjCQpTybiJUAUNTFTxlDMpTVPDv0ZYAzE,11206
12
12
  amazon_echo/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- python_amazon_echo-0.3.1.dist-info/METADATA,sha256=m2ILh-YpRt36B1OV0Gx-a7RDkzdOtFLBLXbZMXZgheE,17932
14
- python_amazon_echo-0.3.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
15
- python_amazon_echo-0.3.1.dist-info/entry_points.txt,sha256=rbZJ8BI8kkiDTV9cKk6acbHuyAm2xNYfpDBXQNw8Yb8,58
16
- python_amazon_echo-0.3.1.dist-info/licenses/LICENSE,sha256=4Zgd3fbLJqWSkwKA-hh1rNN6DC9tNQ3rWLX93fingOw,1071
17
- python_amazon_echo-0.3.1.dist-info/RECORD,,
13
+ python_amazon_echo-0.3.3.dist-info/METADATA,sha256=CITNiYWVyQ2xNuj1n9AxnS8MalcTeYlbSrUUY4yWzTw,18180
14
+ python_amazon_echo-0.3.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
15
+ python_amazon_echo-0.3.3.dist-info/entry_points.txt,sha256=rbZJ8BI8kkiDTV9cKk6acbHuyAm2xNYfpDBXQNw8Yb8,58
16
+ python_amazon_echo-0.3.3.dist-info/licenses/LICENSE,sha256=4Zgd3fbLJqWSkwKA-hh1rNN6DC9tNQ3rWLX93fingOw,1071
17
+ python_amazon_echo-0.3.3.dist-info/RECORD,,