Skip to content

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

Merged
rabits merged 2 commits into
rabits:mainfrom
GnoX:fix/auth-handshake-stuck-initializing
Jun 6, 2026
Merged

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

Conversation

@GnoX

@GnoX GnoX commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

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

@rabits rabits left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah those ble issues are quite hard. I hope this will help... Great change!

@rabits rabits merged commit 1fb616d into rabits:main Jun 6, 2026
4 checks passed
@GnoX GnoX deleted the fix/auth-handshake-stuck-initializing branch June 6, 2026 17:15
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

2 participants