Fix incorrect Bluetooth source address when restoring data from D-Bus (#136862)
parent
0f97747d27
commit
9c0fa327a6
|
@ -39,6 +39,10 @@ def async_load_history_from_system(
|
|||
now_monotonic = monotonic_time_coarse()
|
||||
connectable_loaded_history: dict[str, BluetoothServiceInfoBleak] = {}
|
||||
all_loaded_history: dict[str, BluetoothServiceInfoBleak] = {}
|
||||
adapter_to_source_address = {
|
||||
adapter: details[ADAPTER_ADDRESS]
|
||||
for adapter, details in adapters.adapters.items()
|
||||
}
|
||||
|
||||
# Restore local adapters
|
||||
for address, history in adapters.history.items():
|
||||
|
@ -50,7 +54,11 @@ def async_load_history_from_system(
|
|||
BluetoothServiceInfoBleak.from_device_and_advertisement_data(
|
||||
history.device,
|
||||
history.advertisement_data,
|
||||
history.source,
|
||||
# history.source is really the adapter name
|
||||
# for historical compatibility since BlueZ
|
||||
# does not know the MAC address of the adapter
|
||||
# so we need to convert it to the source address (MAC)
|
||||
adapter_to_source_address.get(history.source, history.source),
|
||||
now_monotonic,
|
||||
True,
|
||||
)
|
||||
|
|
|
@ -426,7 +426,7 @@ async def test_restore_history_from_dbus(
|
|||
address: AdvertisementHistory(
|
||||
ble_device,
|
||||
generate_advertisement_data(local_name="name"),
|
||||
HCI0_SOURCE_ADDRESS,
|
||||
"hci0",
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -438,6 +438,8 @@ async def test_restore_history_from_dbus(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert bluetooth.async_ble_device_from_address(hass, address) is ble_device
|
||||
info = bluetooth.async_last_service_info(hass, address, False)
|
||||
assert info.source == "00:00:00:00:00:01"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("one_adapter")
|
||||
|
|
Loading…
Reference in New Issue