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 GitHub
parent 63b454c9ed
commit 5d7cef6416
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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