Skip to content

Wire rate limiter into Frigidaire via requests.Session#55

Merged
bm1549 merged 4 commits into
mainfrom
fix/wire-up-rate-limiter
May 15, 2026
Merged

Wire rate limiter into Frigidaire via requests.Session#55
bm1549 merged 4 commits into
mainfrom
fix/wire-up-rate-limiter

Conversation

@bm1549
Copy link
Copy Markdown
Owner

@bm1549 bm1549 commented May 13, 2026

Summary

The autowrap added in #45 silently disabled itself. It patched self._session.request, but Frigidaire never created _session — HTTP went through module-level requests.get/post/put. The AttributeError was swallowed by a bare except, so write spacing, 429/Retry-After handling, and the default timeout have all been no-ops in production. Downstream cas_3403 lockouts that #45 was meant to prevent (bm1549/home-assistant-frigidaire#91) were never actually mitigated by 0.1.3+.

This PR inlines the limiter setup into Frigidaire.__init__: create a requests.Session, wrap request before authenticate() runs (so the auth flow is throttled too — the original incident was an auth storm), and route every HTTP call through self._session. The magic kwargs become explicit, typed, kw-only constructor params. rl_autowrap.py is deleted.

A regression test (test_writes_are_rate_limited_through_session) asserts the wrapper actually fires on a real execute_action call, so this can't silently break again.

Test plan

  • pytest — 74 passed in 0.15s
  • ruff check . — clean
  • mypy frigidaire/ — clean
  • Verify with a downstream HA install that scene-driven multi-AC writes no longer trigger cas_3403

🤖 Generated with Claude Code

The autowrap monkey-patched self._session.request, but Frigidaire never
created a _session — it called module-level requests.get/post/put. The
AttributeError was swallowed by a bare except, so the limiter, 429/Retry-After
handling, and default timeout silently did nothing in production since #45
was merged.

Inline the limiter setup into __init__: create a requests.Session, wrap its
request method before authenticate() runs (so auth is throttled too), route
all HTTP calls through self._session, and promote the rate-limit knobs to
explicit kwargs. Drop rl_autowrap.py.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@bm1549
Copy link
Copy Markdown
Owner Author

bm1549 commented May 13, 2026

@karlg100 heads-up — the autowrap added in #45 has been silently disabled in production since it merged. The enable_autowrap patch targets self._session.request, but Frigidaire never created a _session (HTTP went through module-level requests.get/post/put). The AttributeError got swallowed by a bare except Exception: pass, so write spacing, Retry-After handling, and the default timeout were all no-ops — the cas_3403 lockouts from bm1549/home-assistant-frigidaire#91 were never actually mitigated.

This PR wires the limiter in for real. Tagging you in case you want to verify against your 4-AC scene setup once it lands; that was the canonical reproduction.

bm1549 and others added 3 commits May 12, 2026 22:18
- Widen timeout type to float | None to match docstring
- Remove dead self.timeout (no longer read after the Session refactor)
- Drop redundant `or RL_DEFAULT_METHODS` fallback at the call site by
  letting wrap_session_request handle None internally
- Collapse kwargs.update(overrides) into a single dict expression in conftest
- Drop misleading "connect,read" tuple-string support from smoke test
  (the previous ternary silently fell back to 15.0 on tuple input)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
# Conflicts:
#	frigidaire/__init__.py
@bm1549 bm1549 merged commit 8ed264a into main May 15, 2026
4 checks passed
@bm1549 bm1549 deleted the fix/wire-up-rate-limiter branch May 15, 2026 17:53
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.

1 participant