From ae28c604e5dfb516f05581bff60bfabe18e4f788 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 5 May 2024 15:37:10 -0500 Subject: [PATCH] Fix airthings-ble data drop outs when Bluetooth connection is flakey (#116805) * Fix airthings-ble data drop outs when Bluetooth adapter is flakey fixes #116770 * add missing file * update --- homeassistant/components/airthings_ble/__init__.py | 8 +++++++- homeassistant/components/airthings_ble/const.py | 2 ++ homeassistant/components/airthings_ble/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/airthings_ble/__init__.py b/homeassistant/components/airthings_ble/__init__.py index 39617a8a019..219a384bae0 100644 --- a/homeassistant/components/airthings_ble/__init__.py +++ b/homeassistant/components/airthings_ble/__init__.py @@ -16,7 +16,7 @@ from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.util.unit_system import METRIC_SYSTEM -from .const import DEFAULT_SCAN_INTERVAL, DOMAIN +from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, MAX_RETRIES_AFTER_STARTUP PLATFORMS: list[Platform] = [Platform.SENSOR] @@ -61,6 +61,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await coordinator.async_config_entry_first_refresh() + # Once its setup and we know we are not going to delay + # the startup of Home Assistant, we can set the max attempts + # to a higher value. If the first connection attempt fails, + # Home Assistant's built-in retry logic will take over. + airthings.set_max_attempts(MAX_RETRIES_AFTER_STARTUP) + hass.data[DOMAIN][entry.entry_id] = coordinator await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) diff --git a/homeassistant/components/airthings_ble/const.py b/homeassistant/components/airthings_ble/const.py index 96372919e70..fdfebea8bff 100644 --- a/homeassistant/components/airthings_ble/const.py +++ b/homeassistant/components/airthings_ble/const.py @@ -7,3 +7,5 @@ VOLUME_BECQUEREL = "Bq/m³" VOLUME_PICOCURIE = "pCi/L" DEFAULT_SCAN_INTERVAL = 300 + +MAX_RETRIES_AFTER_STARTUP = 5 diff --git a/homeassistant/components/airthings_ble/manifest.json b/homeassistant/components/airthings_ble/manifest.json index d93e3a0b8cb..b86bc314819 100644 --- a/homeassistant/components/airthings_ble/manifest.json +++ b/homeassistant/components/airthings_ble/manifest.json @@ -24,5 +24,5 @@ "dependencies": ["bluetooth_adapters"], "documentation": "https://www.home-assistant.io/integrations/airthings_ble", "iot_class": "local_polling", - "requirements": ["airthings-ble==0.8.0"] + "requirements": ["airthings-ble==0.9.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index 462d33d69d0..e3f2bd0e36c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -413,7 +413,7 @@ aioymaps==1.2.2 airly==1.1.0 # homeassistant.components.airthings_ble -airthings-ble==0.8.0 +airthings-ble==0.9.0 # homeassistant.components.airthings airthings-cloud==0.2.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 5233e7e70f8..27e70c28916 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -386,7 +386,7 @@ aioymaps==1.2.2 airly==1.1.0 # homeassistant.components.airthings_ble -airthings-ble==0.8.0 +airthings-ble==0.9.0 # homeassistant.components.airthings airthings-cloud==0.2.0