Skip to content

Fix integration stuck initializing on stray BLE bytes or link loss during auth#368

Open
GnoX wants to merge 2 commits into
rabits:mainfrom
GnoX:fix/auth-handshake-stuck-initializing
Open

Fix integration stuck initializing on stray BLE bytes or link loss during auth#368
GnoX wants to merge 2 commits into
rabits:mainfrom
GnoX:fix/auth-handshake-stuck-initializing

Conversation

@GnoX
Copy link
Copy Markdown
Collaborator

@GnoX GnoX commented Jun 6, 2026

This PR fixes the integration getting stuck "initializing" indefinitely when the BLE auth handshake hit an unrecoverable state during the ECDH key exchange and never reached a terminal state, leaving async_setup_entry waiting forever. Three separate gaps each let a transient BLE hiccup wedge setup:

  • Stray notification bytes aborted the handshake. SimplePacketAssembler.parse raised PacketParseError on a notification with no \x5a\x5a prefix or only CRC-invalid candidates - typically leftover bytes from the previous encrypted session on a freshly reconnected link. It now returns None ("wait for the next notification") like the encrypted EncPacketAssembler already does, so a stray notification can't abort auth and spin the reconnect loop.
  • Retrying a dead transport hung auth. When the link dropped mid-request (BlueZ Remote peer disconnected from start_notify), sendRequest retried on a transport that was already gone, and bleak doesn't always fire its disconnected callback for a synchronous GATT failure. It now detects the lost link and drives disconnected() itself - scheduling a reconnect, idempotent with bleak's callback.
  • The setup auth wait had no deadline. async_setup_entry is now bounded by asyncio.timeout(timeout) (the same connection timeout, matching the config flow) and disconnects on failure, so a stalled handshake surfaces as ConfigEntryNotReady and HA retries cleanly.

Should resolve #367 and also #366

@GnoX GnoX self-assigned this Jun 6, 2026
@GnoX GnoX added the bug Something isn't working label Jun 6, 2026
@GnoX GnoX marked this pull request as ready for review June 6, 2026 12:39
@GnoX GnoX requested a review from rabits June 6, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Initializing for 5 hours

1 participant