Fix integration stuck initializing on stray BLE bytes or link loss during auth#368
Open
GnoX wants to merge 2 commits into
Open
Fix integration stuck initializing on stray BLE bytes or link loss during auth#368GnoX wants to merge 2 commits into
GnoX wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_entrywaiting forever. Three separate gaps each let a transient BLE hiccup wedge setup:SimplePacketAssembler.parseraisedPacketParseErroron a notification with no\x5a\x5aprefix or only CRC-invalid candidates - typically leftover bytes from the previous encrypted session on a freshly reconnected link. It now returnsNone("wait for the next notification") like the encryptedEncPacketAssembleralready does, so a stray notification can't abort auth and spin the reconnect loop.Remote peer disconnectedfromstart_notify),sendRequestretried on a transport that was already gone, and bleak doesn't always fire itsdisconnectedcallback for a synchronous GATT failure. It now detects the lost link and drivesdisconnected()itself - scheduling a reconnect, idempotent with bleak's callback.async_setup_entryis now bounded byasyncio.timeout(timeout)(the same connection timeout, matching the config flow) and disconnects on failure, so a stalled handshake surfaces asConfigEntryNotReadyand HA retries cleanly.Should resolve #367 and also #366