Skip to content

Fix Victron BLE false reauth on unrecognised advertisement mode bytes#168209

Merged
joostlek merged 2 commits into
home-assistant:devfrom
rajlaud:fix-victron-ble-false-reauth-unrecognised-mode
Apr 17, 2026
Merged

Fix Victron BLE false reauth on unrecognised advertisement mode bytes#168209
joostlek merged 2 commits into
home-assistant:devfrom
rajlaud:fix-victron-ble-false-reauth-unrecognised-mode

Conversation

@rajlaud
Copy link
Copy Markdown
Contributor

@rajlaud rajlaud commented Apr 14, 2026

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 calls detect_device_type() internally, which
returns None). The reauth guard counted this as a key failure, and after 3 such
advertisements 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

  • Bugfix (non-breaking change which fixes an issue)

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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>
@rajlaud rajlaud marked this pull request as ready for review April 14, 2026 16:45
Copilot AI review requested due to automatic review settings April 14, 2026 16:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 joostlek modified the milestones: 2026.4.3, 2026.4.4 Apr 17, 2026
@joostlek joostlek merged commit 0da7c0c into home-assistant:dev Apr 17, 2026
36 of 37 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Victron BLE Expired Key Errors in 2026.4.2

4 participants