Return empty data when OpenUV API call fails (#83089)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
fixes undefined
This commit is contained in:
Aaron Bach 2022-12-02 18:27:33 -07:00 committed by GitHub
parent 4a56461d3c
commit ee0fbae2ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -32,10 +32,10 @@ class InvalidApiKeyMonitor:
async def async_increment(self) -> None:
"""Increment the counter."""
LOGGER.debug("Invalid API key response detected (number %s)", self._count)
async with self._lock:
self._count += 1
if self._count > self.DEFAULT_FAILED_API_CALL_THRESHOLD:
LOGGER.info("Starting reauth after multiple failed API calls")
self._reauth_flow_manager.start_reauth()
async def async_reset(self) -> None:
@ -114,10 +114,11 @@ class OpenUvCoordinator(DataUpdateCoordinator):
"""Fetch data from OpenUV."""
try:
data = await self.update_method()
except InvalidApiKeyError:
except InvalidApiKeyError as err:
await self._invalid_api_key_monitor.async_increment()
raise UpdateFailed(str(err)) from err
except OpenUvError as err:
raise UpdateFailed(f"Error during protection data update: {err}") from err
raise UpdateFailed(str(err)) from err
await self._invalid_api_key_monitor.async_reset()
return cast(dict[str, Any], data["result"])