From 63da42f394ce282133f589b0ac8e3ba7d187df23 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Sat, 3 Feb 2024 18:30:00 -0500 Subject: [PATCH] Prevent Flo devices and entities from going unavailable when a single refresh fails (#109522) * Prevent Flo devices and entities from going unavailable when a single refresh fails * review comment --- homeassistant/components/flo/device.py | 7 ++++++- tests/components/flo/test_device.py | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/flo/device.py b/homeassistant/components/flo/device.py index 7aacb1b262a..3b7469686b4 100644 --- a/homeassistant/components/flo/device.py +++ b/homeassistant/components/flo/device.py @@ -18,6 +18,8 @@ from .const import DOMAIN as FLO_DOMAIN, LOGGER class FloDeviceDataUpdateCoordinator(DataUpdateCoordinator): # pylint: disable=hass-enforce-coordinator-module """Flo device object.""" + _failure_count: int = 0 + def __init__( self, hass: HomeAssistant, api_client: API, location_id: str, device_id: str ) -> None: @@ -43,8 +45,11 @@ class FloDeviceDataUpdateCoordinator(DataUpdateCoordinator): # pylint: disable= await self.send_presence_ping() await self._update_device() await self._update_consumption_data() + self._failure_count = 0 except RequestError as error: - raise UpdateFailed(error) from error + self._failure_count += 1 + if self._failure_count > 3: + raise UpdateFailed(error) from error @property def location_id(self) -> str: diff --git a/tests/components/flo/test_device.py b/tests/components/flo/test_device.py index 5d619f9e91f..6a633c774ed 100644 --- a/tests/components/flo/test_device.py +++ b/tests/components/flo/test_device.py @@ -93,4 +93,8 @@ async def test_device( "homeassistant.components.flo.device.FloDeviceDataUpdateCoordinator.send_presence_ping", side_effect=RequestError, ), pytest.raises(UpdateFailed): + # simulate 4 updates failing + await valve._async_update_data() + await valve._async_update_data() + await valve._async_update_data() await valve._async_update_data()