Fix Victron BLE false reauth on unrecognised advertisement mode bytes#168209
Merged
joostlek merged 2 commits intoApr 17, 2026
Merged
Conversation
Advertisements with mode bytes that detect_device_type does not recognise caused validate_advertisement_key to return False, which the reauth guard counted as a key failure. After 3 such advertisements the integration would incorrectly trigger a reauth flow telling users their key expired. Guard the key check so it only runs on advertisements whose device type is actually recognised by the parser. Unrecognised advertisements are treated as neutral: they neither increment nor reset the failure counter. Fixes home-assistant#168019 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a false reauth flow in the Victron BLE integration by ensuring the “consecutive key failure” counter is only affected by advertisements that the parser can actually classify, preventing unrecognised mode bytes from being treated as key failures.
Changes:
- Guard the reauth/key-validity logic so it only runs for instant-readout (0x10) advertisements with a recognised device type.
- Treat unrecognised advertisements as neutral (do not increment or reset the failure counter).
- Add regression tests/fixtures covering unrecognised-mode advertisements and mixed sequences (bad → bad → unrecognised → bad).
Show a summary per file
| File | Description |
|---|---|
| homeassistant/components/victron_ble/init.py | Adds a recognisability guard (0x10 + detect_device_type) before counting key validation failures for reauth. |
| tests/components/victron_ble/fixtures.py | Adds a BluetoothServiceInfo fixture with an unrecognised mode byte for regression testing. |
| tests/components/victron_ble/test_sensor.py | Adds helpers and tests ensuring unrecognised-mode advertisements are neutral and don’t cause false reauth. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 0
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Victron BLE false reauth trigger by ensuring the “consecutive key failures” counter is only affected by advertisements whose device type is actually recognized by the parser.
Changes:
- Guard the reauth key-validity check to run only on recognizable instant-readout Victron advertisements; treat unrecognized mode bytes as neutral.
- Add a new test fixture representing an unrecognized mode byte advertisement.
- Add regression tests to ensure unrecognized-mode advertisements do not trigger reauth and do not reset/increment the failure counter.
Show a summary per file
| File | Description |
|---|---|
| homeassistant/components/victron_ble/init.py | Updates the reauth guard logic to ignore unrecognized advertisements so they don’t cause false reauth flows. |
| tests/components/victron_ble/fixtures.py | Adds a BLE service-info fixture with an unrecognized mode byte for regression testing. |
| tests/components/victron_ble/test_sensor.py | Adds helper injection + two regression tests covering the neutral behavior and counter semantics. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
joostlek
approved these changes
Apr 17, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Proposed change
Guard the reauth key-validity check so it only runs on BLE advertisements
whose device type
detect_device_type()actually recognises.Advertisements with unrecognised mode bytes caused
validate_advertisement_key()to return
False(because it callsdetect_device_type()internally, whichreturns
None). The reauth guard counted this as a key failure, and after 3 suchadvertisements the integration would incorrectly trigger a reauth flow telling
users their encryption key had expired — even though the key was perfectly valid.
Unrecognised advertisements are now treated as neutral: they neither increment
nor reset the consecutive failure counter.
Type of change
Additional information
Checklist
ruff format homeassistant tests)