Fix Bluetooth discovery for devices with alternating advertisement names #154347
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
Fixes Bluetooth device discovery for devices that alternate advertisement names to work within the 31-byte BLE advertisement size limit.
This PR fixes a bug where Bluetooth devices that alternate their advertised name would not trigger re-discovery. This critically affects devices that must alternate between short names (with sensor data) and full names (with minimal data) due to the 31-byte BLE advertisement constraint.
User impact: Many integrations discover devices by matching
local_namepatterns (e.g.,Govee*,SensorPush*,Inkbird*,Ruuvi *, etc.). Bluetooth LE advertisements are limited to 31 bytes, so devices often alternate between different advertisement packets - some with a short name and sensor data, others with a full name but less data. When the matcher only sees the short name advertisement first, re-discovery does not fire when the full name advertisement is later received, so these devices are never discovered at all if the short name doesn't match the pattern.Example: A SensorPush device alternates advertisements:
s+ temperature/humidity data (fits in 31 bytes)SensorPush HT.w 12345+ minimal data (fits in 31 bytes)Without this fix, if the matcher sees advertisement 1 first, the
sensorpushintegration (which matcheslocal_name: "SensorPush*") never discovers the device because re-discovery doesn't fire when advertisement 2 with the full name arrives.This is standard BLE behavior where devices alternate advertisement content to work within the 31-byte limit.
Root cause: The
IntegrationMatchHistoryclass tracked which advertisement fields (manufacturer_data, service_data, service_uuids) had been seen for each device to optimize matcher performance. However, it did not track the device name. When a device's name changed but other fields remained the same,seen_all_fields()would incorrectly returnTrue, causing an early return with an empty match set instead of re-evaluating the device against matchers.Fix: Added
namefield toIntegrationMatchHistoryand updatedseen_all_fields()to check if the name has changed. When the name changes, the device is now re-evaluated against all matchers, triggering a second discovery that allows integrations to update the device information.Example scenario:
SensorPush device alternating advertisements:
s+ sensor data → no match (doesn't matchSensorPush*pattern)SensorPush HT.w 12345+ minimal data → previously returned empty match, device never discoveredsensorpushby name pattern, device is discoveredThis same issue affects many other integrations that match by
local_namepattern including Govee, Inkbird, Ruuvi, and dozens of others listed in bluetooth.py.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: