Drop Home Assistant per-entity staleness check (delegate to integration)#365
Conversation
The 60 s per-entity timer and its REST-based last_reported fallback were chasing a problem the integration layer already owns. HA integrations set their sensors to unavailable/unknown when their upstream source goes silent (ESPHome device offline, ha-tibber-pulse-local websocket dead, etc.); _update_entity_value already converts those to None, which _get_entity_value already raises on. Constant numeric values are legitimate steady-state behaviour and must not be flagged. This also covers the push-based integration case (issue #363 follow-up): when a smart meter pushes only on value changes, HA's last_reported stays old too, so the merged REST fallback bailed and re-raised the same false stale error. Trusting unavailable/unknown is the only correct freshness signal here. aiohttp's websocket heartbeat (30 s) still catches dead TCP and triggers reconnect; the reconnect block now invalidates cached values so callers can't serve them across an extended outage. Net: ~600 lines removed (staleness machinery + REST fallback + tests).
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- Extract _ws_loop reset block into _reset_for_reconnect so the test drives the real method rather than open-coding the same four statements: a regression in the production reset is now caught. - Parametrize state_reported wake test over both lu and lc, and assert the cached numeric value is preserved (keepalive carries no s). - Add test_unavailable_blocks_wait_for_message covering the consequence of a sensor going unavailable mid-stream: wait_for_message must block again instead of returning the cached "ready" flag.
- Move the power_input_alias / power_output_alias length-mismatch ValueError from get_powermeter_watts into __init__. The aliases are a static config invariant; fail fast at construction instead of on every call. - Reword the CHANGELOG bullet to make the goal explicit: a sensor is treated as stale only when HA marks it unavailable/unknown or the websocket is lost. Mentions push-based integrations alongside the constant-value case so readers don't think the fix is only about rare edge cases.
Summary
Follow-up to #364 for #363. The 60 s per-entity timer and the REST
last_reportedfallback merged in #364 close the ESPHome/Slimmelezer case but not the push-based case @DerDaehne flagged: when a smart meter (e.g.ha-tibber-pulse-local) only pushes on value changes, HA'slast_reportedstays old too, so the REST fallback bails and re-raises the same false stale error.HA integrations already own this signal. They set sensors to
unavailable/unknownwhen their upstream source dies (ESPHome device offline, tibber-pulse websocket dead, etc.), and_update_entity_valuealready converts those toNone, on which_get_entity_valuealready raises. A constant numeric value is legitimate steady-state behaviour — there's nothing for us to check on top.This PR removes the timer, the REST fallback, the wall-clock parsing of
last_reported, the injectableclock, andmax_state_age_seconds. Net ~600 lines deleted.aiohttp's WebSocket heartbeat (30 s) still catches dead TCP and triggers reconnect; the reconnect block now invalidates cached values to
Noneso callers can't serve them across an extended outage.Test plan
uv run ruff format . && uv run ruff check .— cleanuv run mypy src/— cleanuv run pytest— 671 passed, 27 skippedhttps://claude.ai/code/session_01LwA9fBRZcLjRi7fEU4fHyw
Generated by Claude Code