Skip to content

Fix: bound initial connect to avoid setup CancelledError (v0.3.1)#3

Merged
magicx78 merged 1 commit into
mainfrom
fix/setup-cancelled-timeout
Jun 4, 2026
Merged

Fix: bound initial connect to avoid setup CancelledError (v0.3.1)#3
magicx78 merged 1 commit into
mainfrom
fix/setup-cancelled-timeout

Conversation

@magicx78

@magicx78 magicx78 commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Problem: On production HAOS the setup failed with a raw asyncio.CancelledError (Setup of config entry 'HLK-LD2450_1B6F' ... cancelled). Root cause: establish_connection can block for minutes when the BLE proxy/device is briefly unreachable, so Home Assistant's bootstrap stage timeout cancels async_setup_entry (we only caught BLEAK_EXCEPTIONS, not cancellation).

Fix (matches core led_ble/yalexs_ble):

  • Wrap device.initialise() in asyncio.timeout(DEVICE_TIMEOUT=30s) and raise ConfigEntryNotReady on TimeoutError (caught before BLEAK_EXCEPTIONS, which also contains asyncio.TimeoutError). HA then retries cleanly instead of cancelling.
  • CancelledError is deliberately never swallowed.
  • establish_connection(max_attempts=3) so connect failures surface promptly.

Tests: new cannot_connect + connect_timeout setup tests. ruff clean, 44 pytest pass.

Releases as v0.3.1 (manifest bumped, CHANGELOG).

Wrap device.initialise() in asyncio.timeout(DEVICE_TIMEOUT=30s) and raise ConfigEntryNotReady on TimeoutError (before BLEAK_EXCEPTIONS). CancelledError is never swallowed. establish_connection(max_attempts=3) so failures surface promptly. Matches core led_ble/yalexs_ble. Adds cannot_connect + connect_timeout tests; ruff + 44 pytest pass.
@magicx78 magicx78 merged commit ae57611 into main Jun 4, 2026
6 checks passed
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.

2 participants