From b12291633ca04c76c801123f5192d4e5c2e2b9f8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 11 Jan 2024 22:56:52 -1000 Subject: [PATCH] Fix ld2410_ble not being able to setup because it has a stale connection (#107754) --- homeassistant/components/ld2410_ble/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/ld2410_ble/__init__.py b/homeassistant/components/ld2410_ble/__init__.py index e127a4a9836..57e3dfa4617 100644 --- a/homeassistant/components/ld2410_ble/__init__.py +++ b/homeassistant/components/ld2410_ble/__init__.py @@ -2,7 +2,11 @@ import logging -from bleak_retry_connector import BleakError, close_stale_connections, get_device +from bleak_retry_connector import ( + BleakError, + close_stale_connections_by_address, + get_device, +) from ld2410_ble import LD2410BLE from homeassistant.components import bluetooth @@ -24,6 +28,9 @@ _LOGGER = logging.getLogger(__name__) async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up LD2410 BLE from a config entry.""" address: str = entry.data[CONF_ADDRESS] + + await close_stale_connections_by_address(address) + ble_device = bluetooth.async_ble_device_from_address( hass, address.upper(), True ) or await get_device(address) @@ -32,8 +39,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: f"Could not find LD2410B device with address {address}" ) - await close_stale_connections(ble_device) - ld2410_ble = LD2410BLE(ble_device) coordinator = LD2410BLECoordinator(hass, ld2410_ble)