Skip to content

Expose async_clear_advertisement_history in the bluetooth API#169191

Merged
frenck merged 2 commits into
devfrom
bluetooth-async-clear-advertisement-history
Apr 29, 2026
Merged

Expose async_clear_advertisement_history in the bluetooth API#169191
frenck merged 2 commits into
devfrom
bluetooth-async-clear-advertisement-history

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented Apr 26, 2026

Proposed change

Adds a thin wrapper around BluetoothManager.async_clear_advertisement_history so integrations have a supported way to clear cached advertisement history for a device; the next advertisement from that address is then treated as new data, bypassing the change-detection guard in the Bluetooth manager. Useful for devices that emit a static "I am awake" advertisement after a GATT session ends, where the deduplicator would otherwise hide the next wake-up packet from the integration's callback. The underlying habluetooth method has been available since habluetooth 5.11.0; this PR only exposes it through homeassistant.components.bluetooth.

Background discussion: Bluetooth-Devices/habluetooth#397

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

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][dev-checklist]
  • I have followed the [perfect PR recommendations][perfect-pr]
  • 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:

  • Documentation added/updated for [www.home-assistant.io][docs-repository]

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

  • The [manifest file][manifest-docs] 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.

Adds a thin wrapper so integrations can clear cached advertisement
history for a device, causing the next advertisement from that
address to be treated as new data and bypass the change-detection
guard in the Bluetooth manager.
Copilot AI review requested due to automatic review settings April 26, 2026 12:39
@home-assistant home-assistant Bot added cla-signed has-tests integration: bluetooth new-feature small-pr PRs with less than 30 lines. Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage Top 50 Integration is ranked within the top 50 by usage by-code-owner Quality Scale: internal labels Apr 26, 2026
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

Exposes a new supported Bluetooth API helper to clear per-device advertisement deduplication history, enabling integrations to re-receive “identical” advertisements after a device wake-up / GATT session.

Changes:

  • Add async_clear_advertisement_history(hass, address) to homeassistant.components.bluetooth.api.
  • Re-export the new API from homeassistant.components.bluetooth.
  • Add a regression test asserting that clearing history causes the next identical advertisement to be delivered to callbacks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
homeassistant/components/bluetooth/api.py Adds a @hass_callback wrapper around the manager’s async_clear_advertisement_history.
homeassistant/components/bluetooth/__init__.py Re-exports the new API function as part of the public bluetooth module surface.
tests/components/bluetooth/test_init.py Adds coverage validating dedup behavior before/after clearing advertisement history.

@frenck frenck merged commit 0dfbe3e into dev Apr 29, 2026
48 checks passed
@frenck frenck deleted the bluetooth-async-clear-advertisement-history branch April 29, 2026 08:11
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

by-code-owner cla-signed has-tests integration: bluetooth new-feature Quality Scale: internal small-pr PRs with less than 30 lines. Top 50 Integration is ranked within the top 50 by usage Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants