hatch-rest-api 1.41.0__tar.gz → 1.41.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.
Files changed (47) hide show
  1. {hatch_rest_api-1.41.0/src/hatch_rest_api.egg-info → hatch_rest_api-1.41.2}/PKG-INFO +4 -3
  2. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/pyproject.toml +22 -7
  3. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/aws_http.py +3 -2
  4. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/const.py +1 -1
  5. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/hatch.py +33 -18
  6. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/live_smoke_test.py +1 -1
  7. hatch_rest_api-1.41.2/src/hatch_rest_api/py.typed +0 -0
  8. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/rest_baby.py +10 -10
  9. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/rest_iot.py +15 -9
  10. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/rest_mini.py +5 -5
  11. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/rest_plus.py +13 -13
  12. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/restore.py +1 -1
  13. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/restore_iot.py +4 -4
  14. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/restore_v5.py +7 -7
  15. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/scheduled_routine.py +31 -5
  16. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/shadow_client_subscriber.py +6 -2
  17. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/types.py +3 -3
  18. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/util_bootstrap.py +2 -2
  19. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2/src/hatch_rest_api.egg-info}/PKG-INFO +4 -3
  20. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api.egg-info/SOURCES.txt +2 -0
  21. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api.egg-info/requires.txt +1 -1
  22. hatch_rest_api-1.41.2/tests/test_typing_fixes.py +93 -0
  23. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/LICENSE +0 -0
  24. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/README.md +0 -0
  25. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/setup.cfg +0 -0
  26. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/__init__.py +0 -0
  27. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/callbacks.py +0 -0
  28. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/contentful.py +0 -0
  29. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/errors.py +0 -0
  30. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/restore_v4.py +0 -0
  31. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/util.py +0 -0
  32. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api/util_http.py +0 -0
  33. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api.egg-info/dependency_links.txt +0 -0
  34. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/src/hatch_rest_api.egg-info/top_level.txt +0 -0
  35. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_auth_error.py +0 -0
  36. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_const.py +0 -0
  37. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_live_smoke_test.py +0 -0
  38. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_rest_iot_light_and_sound.py +0 -0
  39. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_restore.py +0 -0
  40. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_restore_alarms.py +0 -0
  41. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_restore_controls.py +0 -0
  42. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_restore_v5_clock_schedule_time.py +0 -0
  43. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_restore_v5_clock_tap.py +0 -0
  44. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_restore_v5_clock_turn_off_mode.py +0 -0
  45. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_scheduled_routine.py +0 -0
  46. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_shadow_client_subscriber.py +0 -0
  47. {hatch_rest_api-1.41.0 → hatch_rest_api-1.41.2}/tests/test_util_bootstrap.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hatch_rest_api
3
- Version: 1.41.0
3
+ Version: 1.41.2
4
4
  Summary: Hatch Rest mini Api Wrapper
5
5
  Author-email: Brendan Dahl <dahl.brendan@gmail.com>
6
6
  License-Expression: MIT
@@ -10,12 +10,13 @@ Keywords: hatch,rest-mini,api
10
10
  Classifier: Development Status :: 4 - Beta
11
11
  Classifier: Natural Language :: English
12
12
  Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
13
14
  Classifier: Programming Language :: Python :: 3.14
14
15
  Classifier: Operating System :: MacOS :: MacOS X
15
- Requires-Python: <4,>=3.14.0
16
+ Requires-Python: <4,>=3.14
16
17
  Description-Content-Type: text/markdown
17
18
  License-File: LICENSE
18
- Requires-Dist: aiohttp>=3.8.1
19
+ Requires-Dist: aiohttp>=3.13.0
19
20
  Requires-Dist: awsiotsdk>=1.16.0
20
21
  Dynamic: license-file
21
22
 
@@ -10,16 +10,18 @@ authors = [
10
10
  ]
11
11
  description = "Hatch Rest mini Api Wrapper"
12
12
  readme = "README.md"
13
- requires-python = ">=3.14.0, <4"
13
+ requires-python = ">=3.14, <4"
14
14
  license = "MIT"
15
15
  dependencies = [
16
- "aiohttp>=3.8.1",
17
- "awsiotsdk>=1.16.0"
16
+ # 3.13.0 is the first aiohttp release with Python 3.14 wheels.
17
+ "aiohttp>=3.13.0",
18
+ "awsiotsdk>=1.16.0",
18
19
  ]
19
20
  classifiers = [
20
21
  "Development Status :: 4 - Beta",
21
22
  "Natural Language :: English",
22
23
  "Intended Audience :: Developers",
24
+ "Programming Language :: Python :: 3",
23
25
  "Programming Language :: Python :: 3.14",
24
26
  "Operating System :: MacOS :: MacOS X",
25
27
  ]
@@ -59,16 +61,18 @@ where = ["src"]
59
61
  [tool.setuptools.dynamic]
60
62
  version = { attr = "hatch_rest_api.const.VERSION" }
61
63
 
64
+ [tool.setuptools.package-data]
65
+ hatch_rest_api = ["py.typed"]
66
+
62
67
  [tool.mypy]
63
68
  python_version = "3.14"
64
69
  # Scoped to the library only, matching blueair_api: the test suite relies on
65
70
  # duck-typed fakes passed where device classes are expected, which doesn't
66
- # type-check without a disproportionate rewrite. mypy is not yet part of
67
- # scripts/lint or CI: the library still has existing type errors to fix first,
68
- # after which scripts/lint and a py.typed marker can follow carrier_api.
71
+ # type-check without a disproportionate rewrite.
69
72
  files = ["src/hatch_rest_api"]
70
73
  mypy_path = "src"
71
- check_untyped_defs = true
74
+ # Strict mode, matching carrier_api. It implies check_untyped_defs.
75
+ strict = true
72
76
  explicit_package_bases = true
73
77
  pretty = true
74
78
  show_error_codes = true
@@ -76,6 +80,7 @@ warn_unused_configs = true
76
80
 
77
81
  [[tool.mypy.overrides]]
78
82
  module = [
83
+ "_awscrt",
79
84
  "awscrt.*",
80
85
  "awsiot.*",
81
86
  ]
@@ -201,6 +206,16 @@ addopts = """
201
206
  """
202
207
  testpaths = ["tests"]
203
208
  asyncio_mode = "auto"
209
+ # Silences pytest-asyncio's own PytestDeprecationWarning about this
210
+ # option being unset; without it, filterwarnings below turns that
211
+ # warning into a collection-time error before any test can run.
212
+ asyncio_default_fixture_loop_scope = "function"
213
+ # Surface latent deprecations (e.g. bool(NotImplemented), which raises
214
+ # TypeError on 3.14+) while they are still warnings, before they become
215
+ # hard errors in a future Python or dependency release.
216
+ filterwarnings = [
217
+ "error::DeprecationWarning",
218
+ ]
204
219
 
205
220
  [tool.coverage.run]
206
221
  branch = true
@@ -29,7 +29,7 @@ class AwsHttp:
29
29
 
30
30
  @request_with_logging
31
31
  async def _post_request_with_logging_and_errors_raised(
32
- self, url: str, json_body: dict, headers: dict | None = None
32
+ self, url: str, json_body: dict[str, Any], headers: dict[str, str] | None = None
33
33
  ) -> ClientResponse:
34
34
  return await self.api_session.post(url=url, json=json_body, headers=headers)
35
35
 
@@ -64,4 +64,5 @@ class AwsHttp:
64
64
  url=url, json_body=json_body, headers=headers
65
65
  )
66
66
  data = await response.read()
67
- return json.loads(data)
67
+ credentials: dict[str, Any] = json.loads(data)
68
+ return credentials
@@ -2,7 +2,7 @@
2
2
 
3
3
  from enum import Enum
4
4
 
5
- VERSION: str = "1.41.0"
5
+ VERSION: str = "1.41.2"
6
6
 
7
7
  SENSITIVE_FIELD_NAMES = [
8
8
  "username",
@@ -75,6 +75,12 @@ def request_with_logging_and_errors(
75
75
  return request_with_logging_wrapper
76
76
 
77
77
 
78
+ def _scheduled_routine_display_order(routine: ScheduledRoutineAlarm) -> float:
79
+ """Sort key putting routines without a ``displayOrder`` last."""
80
+ display_order = routine.get("displayOrder")
81
+ return float("inf") if display_order is None else display_order
82
+
83
+
78
84
  class Hatch:
79
85
  """Async client for the Hatch REST API at data.hatchbaby.com."""
80
86
 
@@ -93,9 +99,9 @@ class Hatch:
93
99
  @request_with_logging_and_errors
94
100
  @request_with_logging
95
101
  async def _post_request_with_logging_and_errors_raised(
96
- self, url: str, json_body: dict | list, auth_token: str | None = None
102
+ self, url: str, json_body: dict[str, Any] | list[Any], auth_token: str | None = None
97
103
  ) -> ClientResponse:
98
- headers = {USER_AGENT: "hatch_rest_api"}
104
+ headers: dict[str, str] = {USER_AGENT: "hatch_rest_api"}
99
105
  if auth_token is not None:
100
106
  headers["X-HatchBaby-Auth"] = auth_token
101
107
  return await self.api_session.post(url=url, json=json_body, headers=headers)
@@ -103,9 +109,9 @@ class Hatch:
103
109
  @request_with_logging
104
110
  @request_with_logging_and_errors
105
111
  async def _get_request_with_logging_and_errors_raised(
106
- self, url: str, auth_token: str | None = None, params: dict | None = None
112
+ self, url: str, auth_token: str | None = None, params: dict[str, Any] | None = None
107
113
  ) -> ClientResponse:
108
- headers = {USER_AGENT: "hatch_rest_api"}
114
+ headers: dict[str, str] = {USER_AGENT: "hatch_rest_api"}
109
115
  if auth_token is not None:
110
116
  headers["X-HatchBaby-Auth"] = auth_token
111
117
  return await self.api_session.get(url=url, headers=headers, params=params)
@@ -129,7 +135,8 @@ class Hatch:
129
135
  url=url, json_body=json_body
130
136
  )
131
137
  response_json = await response.json()
132
- return response_json["token"]
138
+ token: str = response_json["token"]
139
+ return token
133
140
 
134
141
  async def member(self, auth_token: str) -> dict[str, Any]:
135
142
  """Return the account member details."""
@@ -138,7 +145,8 @@ class Hatch:
138
145
  url=url, auth_token=auth_token
139
146
  )
140
147
  response_json = await response.json()
141
- return response_json["payload"]
148
+ payload: dict[str, Any] = response_json["payload"]
149
+ return payload
142
150
 
143
151
  async def iot_devices(self, auth_token: str) -> list[dict[str, Any]]:
144
152
  """Return the account's IoT devices for every supported product."""
@@ -161,7 +169,8 @@ class Hatch:
161
169
  url=url, auth_token=auth_token, params=params
162
170
  )
163
171
  response_json = await response.json()
164
- return response_json["payload"]
172
+ payload: list[dict[str, Any]] = response_json["payload"]
173
+ return payload
165
174
 
166
175
  async def token(self, auth_token: str) -> dict[str, Any]:
167
176
  """Return the AWS IoT token payload (region, identity id and token)."""
@@ -170,7 +179,8 @@ class Hatch:
170
179
  url=url, auth_token=auth_token
171
180
  )
172
181
  response_json = await response.json()
173
- return response_json["payload"]
182
+ payload: dict[str, Any] = response_json["payload"]
183
+ return payload
174
184
 
175
185
  async def favorites(self, auth_token: str, mac: str) -> list[dict[str, Any]]:
176
186
  """Return the favorites for a device, sorted by display order."""
@@ -180,7 +190,7 @@ class Hatch:
180
190
  url=url, auth_token=auth_token, params=params
181
191
  )
182
192
  response_json = await response.json()
183
- favorites = response_json["payload"]
193
+ favorites: list[dict[str, Any]] = response_json["payload"]
184
194
  favorites.sort(key=lambda x: x.get("displayOrder", float("inf")))
185
195
  return favorites
186
196
 
@@ -192,7 +202,7 @@ class Hatch:
192
202
  url=url, auth_token=auth_token, params=params
193
203
  )
194
204
  response_json = await response.json()
195
- routines = response_json["payload"]
205
+ routines: list[dict[str, Any]] = response_json["payload"]
196
206
  routines.sort(key=lambda x: x.get("displayOrder", float("inf")))
197
207
  return routines
198
208
 
@@ -220,8 +230,8 @@ class Hatch:
220
230
  url=url, auth_token=auth_token, params=params
221
231
  )
222
232
  response_json = await response.json()
223
- routines = response_json["payload"]
224
- routines.sort(key=lambda x: x.get("displayOrder", float("inf")))
233
+ routines: list[ScheduledRoutineAlarm] = response_json["payload"]
234
+ routines.sort(key=_scheduled_routine_display_order)
225
235
  return routines
226
236
 
227
237
  async def update_scheduled_routine_alarm_enabled(
@@ -345,7 +355,8 @@ class Hatch:
345
355
  },
346
356
  )
347
357
  response_json = await response.json()
348
- return response_json["payload"]
358
+ payload: dict[str, Any] = response_json["payload"]
359
+ return payload
349
360
 
350
361
  async def confirm_data_version(
351
362
  self,
@@ -379,7 +390,8 @@ class Hatch:
379
390
  },
380
391
  )
381
392
  response_json = await response.json()
382
- return response_json["payload"]
393
+ payload: list[ScheduledRoutineAlarm] = response_json["payload"]
394
+ return payload
383
395
 
384
396
  async def restore_alarms(
385
397
  self, auth_token: str, mac: str, base_url: str = API_URL
@@ -398,7 +410,8 @@ class Hatch:
398
410
  url=f"{base_url}service/app/alarm/v1/fetch/{mac}", auth_token=auth_token
399
411
  )
400
412
  response_json = await response.json()
401
- return response_json["payload"]
413
+ payload: list[dict[str, Any]] = response_json["payload"]
414
+ return payload
402
415
 
403
416
  async def create_restore_alarm(
404
417
  self, auth_token: str, alarm: dict[str, Any], base_url: str = API_URL
@@ -419,7 +432,8 @@ class Hatch:
419
432
  json_body=alarm,
420
433
  )
421
434
  response_json = await response.json()
422
- return response_json["payload"]
435
+ payload: list[dict[str, Any]] = response_json["payload"]
436
+ return payload
423
437
 
424
438
  async def update_restore_alarms(
425
439
  self, auth_token: str, alarms: list[dict[str, Any]], base_url: str = API_URL
@@ -440,7 +454,8 @@ class Hatch:
440
454
  json_body=alarms,
441
455
  )
442
456
  response_json = await response.json()
443
- return response_json["payload"]
457
+ payload: list[dict[str, Any]] = response_json["payload"]
458
+ return payload
444
459
 
445
460
  async def content(
446
461
  self, auth_token: str, product: str, content: list[str], max_retries: int = 3
@@ -465,7 +480,7 @@ class Hatch:
465
480
  response: ClientResponse = await self._get_request_with_logging_and_errors_raised(
466
481
  url=url, auth_token=auth_token, params=params
467
482
  )
468
- response_json = await response.json()
483
+ response_json: dict[str, dict[str, Any]] = await response.json()
469
484
  return response_json["payload"]
470
485
  except RateError:
471
486
  retry_count += 1
@@ -165,7 +165,7 @@ class SmokeTestTranscript:
165
165
  self._transcript: TextIO | None = None
166
166
  self._stdout: TextIO | None = None
167
167
  self._stderr: TextIO | None = None
168
- self._original_handler_streams: list[tuple[logging.StreamHandler, TextIO]] = []
168
+ self._original_handler_streams: list[tuple[logging.StreamHandler[TextIO], TextIO]] = []
169
169
 
170
170
  def __enter__(self) -> None:
171
171
  """Start teeing stdout, stderr, and logger streams."""
File without changes
@@ -27,15 +27,15 @@ _LOGGER = logging.getLogger(__name__)
27
27
  class RestBaby(ShadowClientSubscriberMixin):
28
28
  """Hatch Rest Baby sound machine and night light."""
29
29
 
30
- audio_track: RestBabyAudioTrack = None
31
- firmware_version: str = None
30
+ audio_track: RestBabyAudioTrack | None = None
31
+ firmware_version: str | None = None
32
32
  volume: int = 0
33
33
 
34
34
  is_online: bool = False
35
35
  current_playing: str = "none"
36
36
  current_id: int = 0
37
37
  current_step: int = 0
38
- battery_level: int = None
38
+ battery_level: int | None = None
39
39
  color_id: int = NO_COLOR_ID
40
40
  sound_id: int = NO_SOUND_ID
41
41
  red: int = 0
@@ -43,13 +43,13 @@ class RestBaby(ShadowClientSubscriberMixin):
43
43
  blue: int = 0
44
44
  white: int = 0
45
45
  brightness: int = 0
46
- charging_status: int = (
46
+ charging_status: int | None = (
47
47
  None # Expected values: 0= Not Charging, 3= Charging, plugged in, 5= Charging, on base
48
48
  )
49
- clock: int = None
50
- flags: int = None
49
+ clock: int | None = None
50
+ flags: int | None = None
51
51
  toddler_lock: bool = False
52
- toddler_lock_mode: str = None
52
+ toddler_lock_mode: str | None = None
53
53
 
54
54
  def _update_local_state(self, state: dict[str, Any]) -> None:
55
55
  _LOGGER.debug("update local state: %s, %s", self.device_name, state)
@@ -101,7 +101,7 @@ class RestBaby(ShadowClientSubscriberMixin):
101
101
  _LOGGER.debug("new state:%s", self)
102
102
  self.publish_updates()
103
103
 
104
- def __repr__(self) -> str:
104
+ def __repr__(self) -> dict[str, Any]: # type: ignore[override] # ha_hatch diagnostics read this dict
105
105
  """Return the device state as a dictionary for debugging."""
106
106
  return {
107
107
  "device_name": self.device_name,
@@ -232,9 +232,9 @@ class RestBaby(ShadowClientSubscriberMixin):
232
232
  # Update the map with any changes from the API (in case URLs have changed)
233
233
  sound_url_map.update(
234
234
  {
235
- sound.get("id"): sound.get("wavUrl")
235
+ sound_id: wav_url
236
236
  for sound in self.sounds
237
- if sound.get("id") and sound.get("wavUrl")
237
+ if (sound_id := sound.get("id")) and (wav_url := sound.get("wavUrl"))
238
238
  }
239
239
  )
240
240
  _LOGGER.debug("Available Sounds: %s", sound_url_map)
@@ -28,15 +28,15 @@ _LOGGER = logging.getLogger(__name__)
28
28
  class RestIot(ShadowClientSubscriberMixin):
29
29
  """Hatch Rest 2nd gen sound machine and night light."""
30
30
 
31
- audio_track: RIoTAudioTrack = None
32
- firmware_version: str = None
31
+ audio_track: RIoTAudioTrack | None = None
32
+ firmware_version: str | None = None
33
33
  volume: int = 0
34
34
 
35
35
  is_online: bool = False
36
36
  current_playing: str = "none"
37
37
  current_id: int = 0
38
38
  current_step: int = 0
39
- battery_level: int = None
39
+ battery_level: int | None = None
40
40
  color_id: int = NO_COLOR_ID
41
41
  sound_id: int = NO_SOUND_ID
42
42
  red: int = 0
@@ -44,13 +44,13 @@ class RestIot(ShadowClientSubscriberMixin):
44
44
  blue: int = 0
45
45
  white: int = 0
46
46
  brightness: int = 0
47
- charging_status: int = (
47
+ charging_status: int | None = (
48
48
  None # Expected values: 0= Not Charging, 3= Charging, plugged in, 5= Charging, on base
49
49
  )
50
- clock: int = None
51
- flags: int = None
50
+ clock: int | None = None
51
+ flags: int = 0
52
52
  toddler_lock: bool = False
53
- toddler_lock_mode: str = None
53
+ toddler_lock_mode: str | None = None
54
54
 
55
55
  def _update_local_state(self, state: dict[str, Any]) -> None:
56
56
  _LOGGER.debug("update local state: %s, %s", self.device_name, state)
@@ -102,7 +102,7 @@ class RestIot(ShadowClientSubscriberMixin):
102
102
  _LOGGER.debug("new state:%s", self)
103
103
  self.publish_updates()
104
104
 
105
- def __repr__(self) -> str:
105
+ def __repr__(self) -> dict[str, Any]: # type: ignore[override] # ha_hatch diagnostics read this dict
106
106
  """Return the device state as a dictionary for debugging."""
107
107
  return {
108
108
  "device_name": self.device_name,
@@ -230,7 +230,13 @@ class RestIot(ShadowClientSubscriberMixin):
230
230
 
231
231
  sound_url_map = RIoTAudioTrack.sound_url_map()
232
232
  # update the map with any changes from the API
233
- sound_url_map.update({sound.get("id"): sound.get("wavUrl") for sound in self.sounds})
233
+ sound_url_map.update(
234
+ {
235
+ sound_id: wav_url
236
+ for sound in self.sounds
237
+ if (sound_id := sound.get("id")) and (wav_url := sound.get("wavUrl"))
238
+ }
239
+ )
234
240
  _LOGGER.debug("Available Sounds: %s", sound_url_map)
235
241
  self._update(
236
242
  {
@@ -13,15 +13,15 @@ _LOGGER = logging.getLogger(__name__)
13
13
  class RestMini(ShadowClientSubscriberMixin):
14
14
  """Hatch Rest Mini sound machine."""
15
15
 
16
- firmware_version: str = None
17
- is_online: bool = None
16
+ firmware_version: str | None = None
17
+ is_online: bool | None = None
18
18
 
19
- audio_track: RestMiniAudioTrack = None
20
- volume: int = None
19
+ audio_track: RestMiniAudioTrack | None = None
20
+ volume: int | None = None
21
21
 
22
22
  current_playing: str = "none"
23
23
 
24
- def __repr__(self) -> str:
24
+ def __repr__(self) -> dict[str, Any]: # type: ignore[override] # ha_hatch diagnostics read this dict
25
25
  """Return the device state as a dictionary for debugging."""
26
26
  return {
27
27
  "device_name": self.device_name,
@@ -19,21 +19,21 @@ _LOGGER = logging.getLogger(__name__)
19
19
  class RestPlus(ShadowClientSubscriberMixin):
20
20
  """Hatch Rest+ sound machine and night light."""
21
21
 
22
- firmware_version: str = None
23
- audio_track: RestPlusAudioTrack = None
22
+ firmware_version: str | None = None
23
+ audio_track: RestPlusAudioTrack | None = None
24
24
  volume: int = 0
25
25
 
26
- is_on: bool = None
27
- battery_level: int = None
28
- is_online: bool = None
26
+ is_on: bool | None = None
27
+ battery_level: int | None = None
28
+ is_online: bool | None = None
29
29
 
30
- red: int = None
31
- green: int = None
32
- blue: int = None
33
- brightness: int = None
30
+ red: int | None = None
31
+ green: int | None = None
32
+ blue: int | None = None
33
+ brightness: int | None = None
34
34
 
35
- color_random: bool = None
36
- color_white: bool = None
35
+ color_random: bool | None = None
36
+ color_white: bool | None = None
37
37
 
38
38
  def _update_local_state(self, state: dict[str, Any]) -> None:
39
39
  _LOGGER.debug("update local state: %s, %s", self.device_name, state)
@@ -75,9 +75,9 @@ class RestPlus(ShadowClientSubscriberMixin):
75
75
  @property
76
76
  def is_playing(self) -> bool:
77
77
  """Whether the device is on and a sound track is selected."""
78
- return self.is_on and self.audio_track != RestPlusAudioTrack.NONE
78
+ return bool(self.is_on) and self.audio_track != RestPlusAudioTrack.NONE
79
79
 
80
- def __repr__(self) -> str:
80
+ def __repr__(self) -> dict[str, Any]: # type: ignore[override] # ha_hatch diagnostics read this dict
81
81
  """Return the device state as a dictionary for debugging."""
82
82
  return {
83
83
  "device_name": self.device_name,
@@ -319,7 +319,7 @@ class Restore(ShadowClientSubscriberMixin):
319
319
  _LOGGER.debug("new state:%s", self)
320
320
  self.publish_updates()
321
321
 
322
- def __repr__(self) -> str:
322
+ def __repr__(self) -> dict[str, Any]: # type: ignore[override] # ha_hatch diagnostics read this dict
323
323
  """Return the device state as a dictionary for debugging."""
324
324
  return {
325
325
  "device_name": self.device_name,
@@ -26,8 +26,8 @@ _LOGGER = logging.getLogger(__name__)
26
26
  class RestoreIot(ScheduledRoutineAlarmMixin, ShadowClientSubscriberMixin):
27
27
  """Hatch Restore (1st gen) sunrise alarm, sound machine and light."""
28
28
 
29
- audio_track: str = None
30
- firmware_version: str = None
29
+ audio_track: str | None = None
30
+ firmware_version: str | None = None
31
31
  volume: int = 0
32
32
 
33
33
  is_online: bool = False
@@ -40,7 +40,7 @@ class RestoreIot(ScheduledRoutineAlarmMixin, ShadowClientSubscriberMixin):
40
40
  blue: int = 0
41
41
  white: int = 0
42
42
  brightness: int = 0
43
- charging_status: int = (
43
+ charging_status: int | None = (
44
44
  None # Expected values: 0= Not Charging, 3= Charging, plugged in, 5= Charging, on base
45
45
  )
46
46
  clock: int = 0
@@ -83,7 +83,7 @@ class RestoreIot(ScheduledRoutineAlarmMixin, ShadowClientSubscriberMixin):
83
83
  _LOGGER.debug("new state:%s", self)
84
84
  self.publish_updates()
85
85
 
86
- def __repr__(self) -> str:
86
+ def __repr__(self) -> dict[str, Any]: # type: ignore[override] # ha_hatch diagnostics read this dict
87
87
  """Return the device state as a dictionary for debugging."""
88
88
  return {
89
89
  "device_name": self.device_name,
@@ -31,7 +31,7 @@ _LOGGER = logging.getLogger(__name__)
31
31
  class RestoreV5(ScheduledRoutineAlarmMixin, ShadowClientSubscriberMixin):
32
32
  """Hatch Restore 3 sunrise alarm, sound machine and light."""
33
33
 
34
- firmware_version: str = None
34
+ firmware_version: str | None = None
35
35
  volume: int = 0
36
36
 
37
37
  is_online: bool = False
@@ -48,11 +48,11 @@ class RestoreV5(ScheduledRoutineAlarmMixin, ShadowClientSubscriberMixin):
48
48
  clock_nighttime: int | None = None
49
49
  clock_daytime: int | None = None
50
50
  flags: int = 0
51
- clock_turn_off_mode: str = None
52
- clock_turn_off_at: str = None
53
- clock_turn_on_at: str = None
54
- clock_turn_dim_at: str = None
55
- clock_turn_bright_at: str = None
51
+ clock_turn_off_mode: str | None = None
52
+ clock_turn_off_at: str | None = None
53
+ clock_turn_on_at: str | None = None
54
+ clock_turn_dim_at: str | None = None
55
+ clock_turn_bright_at: str | None = None
56
56
 
57
57
  def _update_local_state(self, state: dict[str, Any]) -> None:
58
58
  _LOGGER.debug("update local state: %s, %s", self.device_name, state)
@@ -106,7 +106,7 @@ class RestoreV5(ScheduledRoutineAlarmMixin, ShadowClientSubscriberMixin):
106
106
  _LOGGER.debug("new state:%s", self)
107
107
  self.publish_updates()
108
108
 
109
- def __repr__(self) -> str:
109
+ def __repr__(self) -> dict[str, Any]: # type: ignore[override] # ha_hatch diagnostics read this dict
110
110
  """Return the device state as a dictionary for debugging."""
111
111
  return {
112
112
  "device_name": self.device_name,
@@ -2,7 +2,7 @@
2
2
 
3
3
  from collections.abc import Iterable
4
4
  from datetime import datetime, time, timedelta
5
- from typing import TYPE_CHECKING, Any, NotRequired, TypedDict
5
+ from typing import TYPE_CHECKING, Any, NotRequired, TypedDict, cast
6
6
 
7
7
  if TYPE_CHECKING:
8
8
  from .hatch import Hatch
@@ -364,7 +364,7 @@ def _next_datetime_for_time(
364
364
  return next_time
365
365
 
366
366
 
367
- def _parse_local_datetime(value: str) -> datetime | None:
367
+ def _parse_local_datetime(value: object) -> datetime | None:
368
368
  if not isinstance(value, str):
369
369
  return None
370
370
  try:
@@ -407,6 +407,16 @@ class ScheduledRoutineAlarmMixin:
407
407
  _alarm_api: Hatch | None = None
408
408
  _alarm_auth_token: str | None = None
409
409
 
410
+ if TYPE_CHECKING:
411
+ # Provided by the device class this mixin is combined with. Declared
412
+ # only for type checking: a runtime stub here would shadow the real
413
+ # publish_updates, since this mixin precedes it in the MRO.
414
+ mac: str
415
+ device_name: str
416
+
417
+ def publish_updates(self) -> None:
418
+ """Run every registered callback."""
419
+
410
420
  def configure_alarm_api(
411
421
  self,
412
422
  api: Hatch,
@@ -481,7 +491,9 @@ class ScheduledRoutineAlarmMixin:
481
491
  if updated_alarms:
482
492
  self._replace_alarms(updated_alarms)
483
493
  else:
484
- self._replace_alarms([{**alarm, **alarm_update_payload(alarm, enabled)}])
494
+ self._replace_alarms(
495
+ [cast("ScheduledRoutineAlarm", {**alarm, **alarm_update_payload(alarm, enabled)})]
496
+ )
485
497
  self.publish_updates()
486
498
 
487
499
  async def set_alarm_wake_time(self, alarm_id: int | str, wake_time: time) -> None:
@@ -511,7 +523,14 @@ class ScheduledRoutineAlarmMixin:
511
523
  if updated_alarms:
512
524
  self._replace_alarms(updated_alarms)
513
525
  else:
514
- self._replace_alarms([{**alarm, **alarm_wake_time_update_payload(alarm, wake_time)}])
526
+ self._replace_alarms(
527
+ [
528
+ cast(
529
+ "ScheduledRoutineAlarm",
530
+ {**alarm, **alarm_wake_time_update_payload(alarm, wake_time)},
531
+ )
532
+ ]
533
+ )
515
534
  self.publish_updates()
516
535
 
517
536
  async def set_alarm_weekdays(
@@ -548,7 +567,14 @@ class ScheduledRoutineAlarmMixin:
548
567
  if updated_alarms:
549
568
  self._replace_alarms(updated_alarms)
550
569
  else:
551
- self._replace_alarms([{**alarm, **alarm_weekdays_update_payload(alarm, weekdays_list)}])
570
+ self._replace_alarms(
571
+ [
572
+ cast(
573
+ "ScheduledRoutineAlarm",
574
+ {**alarm, **alarm_weekdays_update_payload(alarm, weekdays_list)},
575
+ )
576
+ ]
577
+ )
552
578
  self.publish_updates()
553
579
 
554
580
  def _configured_alarm_api(self) -> tuple[Hatch, str]:
@@ -1,7 +1,7 @@
1
1
  """Base class for devices whose state is synced through an AWS IoT device shadow."""
2
2
 
3
3
  import logging
4
- from typing import Any
4
+ from typing import TYPE_CHECKING, Any
5
5
 
6
6
  from awscrt import mqtt
7
7
  from awsiot import iotshadow
@@ -32,13 +32,17 @@ class ShadowClientSubscriberMixin(CallbacksMixin):
32
32
 
33
33
  document_version: int = -1
34
34
 
35
+ if TYPE_CHECKING:
36
+ # Implemented by every device subclass.
37
+ def _update_local_state(self, state: dict[str, Any]) -> None: ...
38
+
35
39
  def __init__(
36
40
  self,
37
41
  device_name: str,
38
42
  thing_name: str,
39
43
  mac: str,
40
44
  shadow_client: IotShadowClient,
41
- favorites: list | None = None,
45
+ favorites: list[Any] | None = None,
42
46
  sounds: list[SoundContent | SimpleSoundContent] | None = None,
43
47
  ) -> None:
44
48
  """Subscribe to the device shadow and request its current state.
@@ -48,9 +48,9 @@ class SoundContent(TypedDict):
48
48
  hatchId: int
49
49
  contentSource: str
50
50
  seriesSize: int
51
- tagIds: list
52
- altTagIds: list
53
- mixIds: list
51
+ tagIds: list[Any]
52
+ altTagIds: list[Any]
53
+ mixIds: list[Any]
54
54
  red: Any | None
55
55
  green: Any | None
56
56
  blue: Any | None
@@ -34,7 +34,7 @@ from .scheduled_routine import (
34
34
  ScheduledRoutineAlarm,
35
35
  ScheduledRoutineAlarmMixin,
36
36
  )
37
- from .types import SimpleSoundContent
37
+ from .types import SimpleSoundContent, SoundContent
38
38
 
39
39
  _LOGGER = logging.getLogger(__name__)
40
40
 
@@ -470,7 +470,7 @@ async def _get_alarms_for_all_scheduled_routine_devices(
470
470
 
471
471
  async def _get_sound_content_for_all_v2_devices(
472
472
  api: Hatch, token: str, contentful: Contentful, iot_devices: list[dict[str, Any]]
473
- ) -> dict[str, list[SimpleSoundContent]]:
473
+ ) -> dict[str, list[SoundContent | SimpleSoundContent]]:
474
474
  mac_to_sounds = {}
475
475
  for device in iot_devices:
476
476
  mac = device["macAddress"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hatch_rest_api
3
- Version: 1.41.0
3
+ Version: 1.41.2
4
4
  Summary: Hatch Rest mini Api Wrapper
5
5
  Author-email: Brendan Dahl <dahl.brendan@gmail.com>
6
6
  License-Expression: MIT
@@ -10,12 +10,13 @@ Keywords: hatch,rest-mini,api
10
10
  Classifier: Development Status :: 4 - Beta
11
11
  Classifier: Natural Language :: English
12
12
  Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
13
14
  Classifier: Programming Language :: Python :: 3.14
14
15
  Classifier: Operating System :: MacOS :: MacOS X
15
- Requires-Python: <4,>=3.14.0
16
+ Requires-Python: <4,>=3.14
16
17
  Description-Content-Type: text/markdown
17
18
  License-File: LICENSE
18
- Requires-Dist: aiohttp>=3.8.1
19
+ Requires-Dist: aiohttp>=3.13.0
19
20
  Requires-Dist: awsiotsdk>=1.16.0
20
21
  Dynamic: license-file
21
22
 
@@ -9,6 +9,7 @@ src/hatch_rest_api/contentful.py
9
9
  src/hatch_rest_api/errors.py
10
10
  src/hatch_rest_api/hatch.py
11
11
  src/hatch_rest_api/live_smoke_test.py
12
+ src/hatch_rest_api/py.typed
12
13
  src/hatch_rest_api/rest_baby.py
13
14
  src/hatch_rest_api/rest_iot.py
14
15
  src/hatch_rest_api/rest_mini.py
@@ -40,4 +41,5 @@ tests/test_restore_v5_clock_tap.py
40
41
  tests/test_restore_v5_clock_turn_off_mode.py
41
42
  tests/test_scheduled_routine.py
42
43
  tests/test_shadow_client_subscriber.py
44
+ tests/test_typing_fixes.py
43
45
  tests/test_util_bootstrap.py
@@ -1,2 +1,2 @@
1
- aiohttp>=3.8.1
1
+ aiohttp>=3.13.0
2
2
  awsiotsdk>=1.16.0
@@ -0,0 +1,93 @@
1
+ """Behavior covered by the strict mypy fixes."""
2
+
3
+ import asyncio
4
+ from typing import Any
5
+ import unittest
6
+ from unittest.mock import AsyncMock, MagicMock
7
+
8
+ from hatch_rest_api.const import RIOT_FLAGS_CLOCK_ON, RestPlusAudioTrack, RIoTAudioTrack
9
+ from hatch_rest_api.hatch import Hatch
10
+ from hatch_rest_api.rest_iot import RestIot
11
+ from hatch_rest_api.rest_plus import RestPlus
12
+
13
+
14
+ def recording_rest_iot(sounds: list[Any]) -> RestIot:
15
+ """A RestIot whose shadow updates are recorded instead of sent."""
16
+ device = RestIot.__new__(RestIot)
17
+ device.device_name = "Rest"
18
+ device.sounds = sounds
19
+ device.sent = []
20
+ device._update = device.sent.append
21
+ return device
22
+
23
+
24
+ class RestIotClockFlagsTest(unittest.TestCase):
25
+ """Clock controls work before the shadow has reported any flags."""
26
+
27
+ def test_set_clock_without_reported_flags(self) -> None:
28
+ """set_clock no longer fails on a None flags default."""
29
+ device = recording_rest_iot([])
30
+ device.set_clock(50)
31
+ assert device.sent[0]["clock"]["flags"] == RIOT_FLAGS_CLOCK_ON
32
+
33
+ def test_turn_clock_off_without_reported_flags(self) -> None:
34
+ """turn_clock_off no longer fails on a None flags default."""
35
+ device = recording_rest_iot([])
36
+ device.turn_clock_off()
37
+ assert device.sent[0]["clock"]["flags"] == RIOT_FLAGS_CLOCK_ON
38
+
39
+
40
+ class RestIotSoundUrlTest(unittest.TestCase):
41
+ """API sounds without a URL do not replace the built-in URL."""
42
+
43
+ def test_sound_without_wav_url_keeps_the_default(self) -> None:
44
+ """A sound with a null wavUrl keeps the hard-coded URL."""
45
+ track = RIoTAudioTrack.BrownNoise
46
+ default_url = RIoTAudioTrack.sound_url_map()[track.value]
47
+ device = recording_rest_iot([{"id": track.value, "title": "Brown", "wavUrl": None}])
48
+ device.set_audio_track(track)
49
+ assert device.sent[0]["current"]["sound"]["url"] == default_url
50
+
51
+ def test_sound_with_wav_url_overrides_the_default(self) -> None:
52
+ """A sound with a wavUrl still overrides the hard-coded URL."""
53
+ track = RIoTAudioTrack.BrownNoise
54
+ device = recording_rest_iot(
55
+ [{"id": track.value, "title": "Brown", "wavUrl": "https://example.invalid/x.wav"}]
56
+ )
57
+ device.set_audio_track(track)
58
+ assert device.sent[0]["current"]["sound"]["url"] == "https://example.invalid/x.wav"
59
+
60
+
61
+ class RestPlusIsPlayingTest(unittest.TestCase):
62
+ """is_playing always returns a bool."""
63
+
64
+ def test_unknown_power_state_is_not_playing(self) -> None:
65
+ """is_playing is False, not None, before the power state is known."""
66
+ device = RestPlus.__new__(RestPlus)
67
+ device.is_on = None
68
+ device.audio_track = RestPlusAudioTrack.Stream
69
+ assert device.is_playing is False
70
+
71
+
72
+ class ScheduledRoutineOrderTest(unittest.TestCase):
73
+ """Scheduled routines sort by displayOrder, with missing values last."""
74
+
75
+ def test_null_display_order_sorts_last(self) -> None:
76
+ """A null displayOrder no longer breaks the sort."""
77
+ response = MagicMock()
78
+ response.json = AsyncMock(
79
+ return_value={
80
+ "payload": [
81
+ {"id": 1, "displayOrder": None},
82
+ {"id": 2},
83
+ {"id": 3, "displayOrder": 2},
84
+ {"id": 4, "displayOrder": 1},
85
+ ]
86
+ }
87
+ )
88
+ api = Hatch(client_session=MagicMock())
89
+ api._get_request_with_logging_and_errors_raised = AsyncMock(return_value=response)
90
+
91
+ routines = asyncio.run(api.scheduled_routines(auth_token="token", mac="AA:BB"))
92
+
93
+ assert [routine["id"] for routine in routines] == [4, 3, 1, 2]
File without changes