Skip to content

Commit 2c980a4

Browse files
committed
fix errors due to missing data
1 parent 301405e commit 2c980a4

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

custom_components/knmi/coordinator.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,19 @@ async def _async_update_data(self) -> dict[str, Any]:
5555
)
5656
# Do not throw an exception unless it's failed a few times to avoid excessive "unavailable" data
5757
# in HASS
58-
if self.failed_update_count > FAILED_UPDATES_ALLOWANCE:
59-
_LOGGER.error(
60-
"Update failed %s times, above limit of %s! - %s",
61-
self.failed_update_count,
62-
FAILED_UPDATES_ALLOWANCE,
63-
exception,
64-
)
65-
raise UpdateFailed() from exception
58+
if self.failed_update_count <= FAILED_UPDATES_ALLOWANCE:
59+
# return the 'old' data on a failed update
60+
_LOGGER.debug("Update failed, returning existing data")
61+
return self.data
62+
63+
# Data update failed too many times, raise an error
64+
_LOGGER.error(
65+
"Update failed %s times, above limit of %s! - %s",
66+
self.failed_update_count,
67+
FAILED_UPDATES_ALLOWANCE,
68+
exception,
69+
)
70+
raise UpdateFailed() from exception
6671

6772
def get_value(self, path: list[int | str], default=None) -> Any:
6873
"""

0 commit comments

Comments
 (0)