Ensure esphome subscribes to bluetooth connection free before accepting connect requests (#90319)

This commit is contained in:
J. Nick Koston 2023-03-26 10:06:14 -10:00 committed by GitHub
parent 916b274ec8
commit 8c9966aa05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,15 +78,18 @@ async def async_connect_scanner(
scanner = ESPHomeScanner(
hass, source, entry.title, new_info_callback, connector, connectable
)
if connectable:
# If its connectable be sure not to register the scanner
# until we know the connection is fully setup since otherwise
# there is a race condition where the connection can fail
await cli.subscribe_bluetooth_connections_free(
entry_data.async_update_ble_connection_limits
)
unload_callbacks = [
async_register_scanner(hass, scanner, connectable),
scanner.async_setup(),
]
await cli.subscribe_bluetooth_le_advertisements(scanner.async_on_advertisement)
if connectable:
await cli.subscribe_bluetooth_connections_free(
entry_data.async_update_ble_connection_limits
)
@hass_callback
def _async_unload() -> None: