Fix race in bluetooth async_process_advertisements (#76176)

This commit is contained in:
J. Nick Koston
2022-08-04 05:58:15 -10:00
committed by Franck Nijhof
parent 11319defae
commit 60da54558e
2 changed files with 4 additions and 1 deletions

View File

@@ -188,7 +188,7 @@ async def async_process_advertisements(
def _async_discovered_device(
service_info: BluetoothServiceInfoBleak, change: BluetoothChange
) -> None:
if callback(service_info):
if not done.done() and callback(service_info):
done.set_result(service_info)
unload = async_register_callback(hass, _async_discovered_device, match_dict, mode)

View File

@@ -856,6 +856,9 @@ async def test_process_advertisements_bail_on_good_advertisement(
)
_get_underlying_scanner()._callback(device, adv)
_get_underlying_scanner()._callback(device, adv)
_get_underlying_scanner()._callback(device, adv)
await asyncio.sleep(0)
result = await handle