Skip to content

fix: replace BleakClient.connect() with establish_connection() and add exponential backoff#6

Open
bpinson999 wants to merge 1 commit into
Chuffnugget:masterfrom
bpinson999:fix/bleak-retry-connector-backoff
Open

fix: replace BleakClient.connect() with establish_connection() and add exponential backoff#6
bpinson999 wants to merge 1 commit into
Chuffnugget:masterfrom
bpinson999:fix/bleak-retry-connector-backoff

Conversation

@bpinson999

Copy link
Copy Markdown

Closes #5

What this fixes
When the vaporizer is unplugged or out of range, the integration spammed the HA log with 126,000+ warning-level entries in a ~2 hour window. See #5 for the full problem description.

Changes
bluetooth_coordinator.py

  • Replace BleakClient.connect() with bleak_retry_connector.establish_connection(), resolving the habluetooth.wrappers warning about unreliable connection establishment
  • Use async_ble_device_from_address() to check HA's Bluetooth registry before attempting a connection — if the device isn't advertising, we return immediately with a DEBUG log instead of a WARNING
  • Catch BleakNotFoundError separately so a powered-off device logs at DEBUG level rather than WARNING
  • Add exponential backoff in _run() (5s base, doubles each failure, 300s cap) to bound retry frequency when the device is unavailable long-term
  • Use asyncio.wait_for(stop_event.wait()) for the backoff sleep so stop() wakes the loop immediately rather than waiting out the full delay
  • Add _on_disconnect callback for clean state reset on unexpected disconnection
  • Accept hass as a constructor argument (required for async_ble_device_from_address)

__init__.py

  • Pass hass into VolcanoBTManager constructor

Tested
Verified with the device unplugged. Backoff progression confirmed in logs (5s → 10s → 20s → ...). No habluetooth.wrappers warnings observed. Zero log spam.

AI Disclosure
This fix was developed with assistance from Claude. All changes were reviewed, tested, and verified by me on a live Home Assistant instance.

…d exponential backoff

- Use bleak_retry_connector.establish_connection() instead of BleakClient.connect()
  directly, resolving the habluetooth.wrappers warning about unreliable connections
- Use async_ble_device_from_address() to check HA BT registry before attempting
  connection; device not advertising now logs at DEBUG instead of WARNING
- Catch BleakNotFoundError separately to avoid noisy WARNING logs when device is off
- Add exponential backoff in _run() loop (5s base, doubles each failure, 300s cap)
  to prevent log spam when device is unavailable for extended periods
- Use asyncio.wait_for(stop_event.wait()) for backoff sleep so stop() wakes the
  loop immediately instead of waiting out the full delay
- Add _on_disconnect callback for clean state reset on unexpected disconnection
- Pass hass instance into VolcanoBTManager constructor
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.

Log spam when device is unavailable: missing bleak-retry-connector and no backoff

1 participant