Conversation
|
@ryanr14 thanks for the PR - please let me know when it's ready to review (it's still in draft, so I'm assuming work still pending) |
|
I think it's ready for review now, @sebr. I added the backoff behavior plus lifecycle guards so pending reconnect timers are cancelled/ignored when the websocket is intentionally stopped, and thought it would be good to add focused websocket tests for backoff, reset, and stop behavior. Codex helped me do that, to be clear. :) I did validate with the ruff format/check and the full pytest suite against current main. |
There was a problem hiding this comment.
Pull request overview
This PR improves the Orbit websocket transport’s reconnect behavior to reduce log spam and load when the upstream websocket endpoint is unhealthy, while continuing to retry until recovery.
Changes:
- Implement exponential backoff for websocket reconnect attempts, capped at 5 minutes, and reset the delay after a successful connection.
- Treat transient websocket handshake HTTP 5xx responses as warnings (rather than generic errors).
- Add targeted unit tests covering backoff behavior, delay reset on success, and reconnect cancellation on stop.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
custom_components/bhyve/pybhyve/websocket.py |
Adds reconnect backoff state/handle tracking, improves handling/logging for transient handshake failures, and resets backoff on successful connect. |
tests/test_websocket.py |
Introduces tests validating exponential backoff, reconnect delay reset after a successful connection, and safe cancellation of pending reconnects on stop. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Why
When the Orbit websocket endpoint returns transient 5xx responses, the integration retries every 5 seconds and can flood Home Assistant logs while the upstream endpoint is unhealthy. The integration should keep retrying, but progressively slow repeated attempts until the endpoint recovers.
Related: #190
Validation
python3 -m py_compile custom_components/bhyve/pybhyve/websocket.pyruff check custom_components/bhyve/pybhyve/websocket.pyruff format --check custom_components/bhyve/pybhyve/websocket.pypython -m pytest tests/test_client.py -q(7 passed)2026.4.4instance, restarted Core, and confirmed the repeated 5-second Orbit websocket502log loop stopped after restart.