Skip to content

Handle 429 rate-limit responses before empty-body fallback#295

Merged
wmalgadey merged 1 commit intowmalgadey:masterfrom
simonachmueller:fix/handle-429-rate-limit-me
Mar 6, 2026
Merged

Handle 429 rate-limit responses before empty-body fallback#295
wmalgadey merged 1 commit intowmalgadey:masterfrom
simonachmueller:fix/handle-429-rate-limit-me

Conversation

@simonachmueller
Copy link

Summary

  • add a dedicated TadoRateLimitException for exhausted API quota responses
  • handle HTTP 429 in Http.request() before the empty-body fallback that currently returns {}
  • include RateLimit-Policy, RateLimit, and Retry-After details in the raised exception message
  • add a regression test for 429 + empty body so /api/v2/me throttling no longer cascades into KeyError('homes')

Why

When Tado rate limits /api/v2/me, responses can be 429 with an empty body. The previous flow returned {} for empty responses and later attempted response[\"homes\"], causing a misleading KeyError.

This PR makes rate-limit exhaustion explicit and actionable.

Closes #294.

Test

  • uv run --with pytest --with responses --with pytest-socket --with typing-extensions --with pydantic python -m pytest tests/test_http.py

@simonachmueller
Copy link
Author

@wmalgadey any chance to take a look?

@wmalgadey wmalgadey merged commit ba491ff into wmalgadey:master Mar 6, 2026
8 checks passed
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 70.58824% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.16%. Comparing base (8b86e5c) to head (2d7d8cd).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
PyTado/http.py 68.75% 1 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #295      +/-   ##
==========================================
- Coverage   76.22%   76.16%   -0.06%     
==========================================
  Files          37       37              
  Lines        2191     2207      +16     
  Branches      129      134       +5     
==========================================
+ Hits         1670     1681      +11     
- Misses        484      485       +1     
- Partials       37       41       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeyError('homes') when /api/v2/me is rate-limited (HTTP 429) during device activation

2 participants