From 805af92ddc5c2468bee882975d0b2d73aeae894f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A5le=20Stor=C3=B8=20Hauknes?= Date: Sat, 30 Dec 2023 23:39:33 +0100 Subject: [PATCH 1/3] Close stale connections --- homeassistant/components/airthings_ble/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/homeassistant/components/airthings_ble/__init__.py b/homeassistant/components/airthings_ble/__init__.py index d7e6bddbcd4e1..23f6c1b262f97 100644 --- a/homeassistant/components/airthings_ble/__init__.py +++ b/homeassistant/components/airthings_ble/__init__.py @@ -5,6 +5,7 @@ import logging from airthings_ble import AirthingsBluetoothDeviceData +from bleak_retry_connector import close_stale_connections from homeassistant.components import bluetooth from homeassistant.config_entries import ConfigEntry @@ -42,6 +43,8 @@ async def _async_update_method(): ble_device = bluetooth.async_ble_device_from_address(hass, address) airthings = AirthingsBluetoothDeviceData(_LOGGER, elevation, is_metric) + close_stale_connections(ble_device) + try: data = await airthings.update_device(ble_device) except Exception as err: From f84db1bc2d51c5775ebd69bebd41ce5146a0e790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A5le=20Stor=C3=B8=20Hauknes?= Date: Sun, 31 Dec 2023 11:44:00 +0100 Subject: [PATCH 2/3] Fix pr comment --- homeassistant/components/airthings_ble/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/airthings_ble/__init__.py b/homeassistant/components/airthings_ble/__init__.py index 23f6c1b262f97..dcb9ce3b1c0b7 100644 --- a/homeassistant/components/airthings_ble/__init__.py +++ b/homeassistant/components/airthings_ble/__init__.py @@ -43,7 +43,7 @@ async def _async_update_method(): ble_device = bluetooth.async_ble_device_from_address(hass, address) airthings = AirthingsBluetoothDeviceData(_LOGGER, elevation, is_metric) - close_stale_connections(ble_device) + await close_stale_connections(ble_device) try: data = await airthings.update_device(ble_device) From d0f2f7168d7f7fe095a4e468e936cbd438892590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A5le=20Stor=C3=B8=20Hauknes?= Date: Wed, 3 Jan 2024 12:12:56 +0100 Subject: [PATCH 3/3] Fix pr comment --- homeassistant/components/airthings_ble/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/airthings_ble/__init__.py b/homeassistant/components/airthings_ble/__init__.py index dcb9ce3b1c0b7..5ea3fb418c217 100644 --- a/homeassistant/components/airthings_ble/__init__.py +++ b/homeassistant/components/airthings_ble/__init__.py @@ -5,7 +5,7 @@ import logging from airthings_ble import AirthingsBluetoothDeviceData -from bleak_retry_connector import close_stale_connections +from bleak_retry_connector import close_stale_connections_by_address from homeassistant.components import bluetooth from homeassistant.config_entries import ConfigEntry @@ -31,6 +31,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: is_metric = hass.config.units is METRIC_SYSTEM assert address is not None + await close_stale_connections_by_address(address) + ble_device = bluetooth.async_ble_device_from_address(hass, address) if not ble_device: @@ -43,8 +45,6 @@ async def _async_update_method(): ble_device = bluetooth.async_ble_device_from_address(hass, address) airthings = AirthingsBluetoothDeviceData(_LOGGER, elevation, is_metric) - await close_stale_connections(ble_device) - try: data = await airthings.update_device(ble_device) except Exception as err: