Wait for a fresh Teslemetry advertisement before connecting over Bluetooth by Bre77 · Pull Request #184193 · home-assistant/core · GitHub
Skip to content

Wait for a fresh Teslemetry advertisement before connecting over Bluetooth - #184193

Merged
silamon merged 8 commits into
home-assistant:devfrom
Teslemetry:fm/teslemetry-ble-scan-race
Oct 6, 2026
Merged

silamon merged 8 commits into
home-assistant:devfrom
Teslemetry:fm/teslemetry-ble-scan-race

Conversation

@Bre77

@Bre77 Bre77 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Breaking change

Proposed change

The Teslemetry "Add local vehicle" Bluetooth step no longer connects at the exact moment its active scan ends, which made a local Bluetooth adapter in the default Auto scanning mode fail instantly on every attempt. When an Auto scanner leaves the scan's active window it restarts discovery, and BlueZ drops the vehicle from that adapter until its next advertisement, so after the scan finds the vehicle the step now waits up to 5 seconds for a connectable advertisement heard once no Auto scanner is still in its active window, then connects. When the vehicle's name is already known from an earlier advertisement, the step skips the active scan and connects straight away. The wait listens with async_register_advertisement_callback, because the change-driven callbacks behind async_process_advertisements are skipped for an advertisement identical to the previous one. When the vehicle is not found, the step logs at debug level the Bluetooth name it looked for, so a debug log shows why setup reported device_not_found.

Please add to beta, milestone 2026.10

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

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.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The connection still uses the stale pre-window BLE device instead of the device from the fresh advertisement.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates Teslemetry Bluetooth pairing to avoid connecting during the adapter’s active-scan transition.

Changes:

  • Waits briefly for a fresh connectable advertisement after active scanning.
  • Skips active scanning when the vehicle is already known.
  • Adds coverage for advertisement timing, timeout, and logging.
File Description
homeassistant/​components/​teslemetry/​config_flow.py Adds post-scan advertisement handling.
homeassistant/​components/​teslemetry/​const.py Defines the advertisement timeout.
tests/​components/​teslemetry/​test_config_flow.py Tests updated scan behavior and diagnostics.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread homeassistant/components/teslemetry/config_flow.py Outdated
@Bre77
Bre77 marked this pull request as draft October 4, 2026 13:19
…-race

# Conflicts:
#	tests/components/teslemetry/test_config_flow.py
Copilot AI balanced review requested due to automatic review settings October 4, 2026 13:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The connection still uses the stale pre-restart BLE handle instead of the fresh advertisement’s device.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

…-race

# Conflicts:
#	homeassistant/components/teslemetry/config_flow.py
#	tests/components/teslemetry/test_config_flow.py
Copilot AI balanced review requested due to automatic review settings October 5, 2026 11:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The fresh advertisement’s device is discarded, allowing connection through the stale pre-restart adapter path.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Copilot AI balanced review requested due to automatic review settings October 5, 2026 11:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The behavior is focused, correctly cleaned up on timeout, and comprehensively tested.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@Bre77
Bre77 marked this pull request as ready for review October 6, 2026 02:41
@silamon
silamon merged commit 7f9d0b9 into home-assistant:dev Oct 6, 2026
37 checks passed
@silamon silamon added this to the 2026.10.0 milestone Oct 6, 2026
@frenck frenck modified the milestone: 2026.10.0 Oct 6, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 7, 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.

4 participants