Fix AccessDeniedException handling in Renault (#104574)

This commit is contained in:
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

View File

@ -45,6 +45,7 @@ class RenaultDataUpdateCoordinator(DataUpdateCoordinator[T]):
) )
self.access_denied = False self.access_denied = False
self.not_supported = False self.not_supported = False
self._has_already_worked = False
async def _async_update_data(self) -> T: async def _async_update_data(self) -> T:
"""Fetch the latest data from the source.""" """Fetch the latest data from the source."""
@ -52,9 +53,14 @@ class RenaultDataUpdateCoordinator(DataUpdateCoordinator[T]):
raise NotImplementedError("Update method not implemented") raise NotImplementedError("Update method not implemented")
try: try:
async with _PARALLEL_SEMAPHORE: 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: 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.update_interval = None
self.access_denied = True self.access_denied = True
raise UpdateFailed(f"This endpoint is denied: {err}") from err raise UpdateFailed(f"This endpoint is denied: {err}") from err