Fix AccessDeniedException handling in Renault (#104574)

pull/104579/head
epenet 2023-11-27 09:19:58 +01:00 committed by GitHub
parent 95c771e330
commit 5ba70ef2cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -45,6 +45,7 @@ class RenaultDataUpdateCoordinator(DataUpdateCoordinator[T]):
)
self.access_denied = False
self.not_supported = False
self._has_already_worked = False
async def _async_update_data(self) -> T:
"""Fetch the latest data from the source."""
@ -52,9 +53,14 @@ class RenaultDataUpdateCoordinator(DataUpdateCoordinator[T]):
raise NotImplementedError("Update method not implemented")
try:
async with _PARALLEL_SEMAPHORE:
return await self.update_method()
data = await self.update_method()
self._has_already_worked = True
return data
except AccessDeniedException as err:
# Disable because the account is not allowed to access this Renault endpoint.
# This can mean both a temporary error or a permanent error. If it has
# worked before, make it temporary, if not disable the update interval.
if not self._has_already_worked:
self.update_interval = None
self.access_denied = True
raise UpdateFailed(f"This endpoint is denied: {err}") from err