mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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:
parent
da29b4ef16
commit
63da42f394
@ -18,6 +18,8 @@ from .const import DOMAIN as FLO_DOMAIN, LOGGER
|
|||||||
class FloDeviceDataUpdateCoordinator(DataUpdateCoordinator): # pylint: disable=hass-enforce-coordinator-module
|
class FloDeviceDataUpdateCoordinator(DataUpdateCoordinator): # pylint: disable=hass-enforce-coordinator-module
|
||||||
"""Flo device object."""
|
"""Flo device object."""
|
||||||
|
|
||||||
|
_failure_count: int = 0
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, api_client: API, location_id: str, device_id: str
|
self, hass: HomeAssistant, api_client: API, location_id: str, device_id: str
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -43,7 +45,10 @@ class FloDeviceDataUpdateCoordinator(DataUpdateCoordinator): # pylint: disable=
|
|||||||
await self.send_presence_ping()
|
await self.send_presence_ping()
|
||||||
await self._update_device()
|
await self._update_device()
|
||||||
await self._update_consumption_data()
|
await self._update_consumption_data()
|
||||||
|
self._failure_count = 0
|
||||||
except RequestError as error:
|
except RequestError as error:
|
||||||
|
self._failure_count += 1
|
||||||
|
if self._failure_count > 3:
|
||||||
raise UpdateFailed(error) from error
|
raise UpdateFailed(error) from error
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -93,4 +93,8 @@ async def test_device(
|
|||||||
"homeassistant.components.flo.device.FloDeviceDataUpdateCoordinator.send_presence_ping",
|
"homeassistant.components.flo.device.FloDeviceDataUpdateCoordinator.send_presence_ping",
|
||||||
side_effect=RequestError,
|
side_effect=RequestError,
|
||||||
), pytest.raises(UpdateFailed):
|
), 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()
|
await valve._async_update_data()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user