mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +00:00
Fix incorrect Bluetooth source address when restoring data from D-Bus (#136862)
This commit is contained in:
parent
5286bd8f0c
commit
edabf0f8dd
@ -39,6 +39,10 @@ def async_load_history_from_system(
|
|||||||
now_monotonic = monotonic_time_coarse()
|
now_monotonic = monotonic_time_coarse()
|
||||||
connectable_loaded_history: dict[str, BluetoothServiceInfoBleak] = {}
|
connectable_loaded_history: dict[str, BluetoothServiceInfoBleak] = {}
|
||||||
all_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
|
# Restore local adapters
|
||||||
for address, history in adapters.history.items():
|
for address, history in adapters.history.items():
|
||||||
@ -50,7 +54,11 @@ def async_load_history_from_system(
|
|||||||
BluetoothServiceInfoBleak.from_device_and_advertisement_data(
|
BluetoothServiceInfoBleak.from_device_and_advertisement_data(
|
||||||
history.device,
|
history.device,
|
||||||
history.advertisement_data,
|
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,
|
now_monotonic,
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
@ -426,7 +426,7 @@ async def test_restore_history_from_dbus(
|
|||||||
address: AdvertisementHistory(
|
address: AdvertisementHistory(
|
||||||
ble_device,
|
ble_device,
|
||||||
generate_advertisement_data(local_name="name"),
|
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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert bluetooth.async_ble_device_from_address(hass, address) is ble_device
|
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")
|
@pytest.mark.usefixtures("one_adapter")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user