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
This commit is contained in:
David F. Mulcahey 2024-02-03 18:30:00 -05:00 committed by GitHub
parent da29b4ef16
commit 63da42f394
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -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,7 +45,10 @@ 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:
self._failure_count += 1
if self._failure_count > 3:
raise UpdateFailed(error) from error
@property

View File

@ -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()