Skip to content

Commit

Permalink
Raise HomeAssistantError if update fails
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeMartin-ICL committed Nov 4, 2024
1 parent 400b377 commit 60b1d71
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions homeassistant/components/monzo/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from dataclasses import dataclass
from datetime import timedelta
import logging
from pprint import pformat
from typing import Any

from monzopy import AuthorisationExpiredError
from monzopy import AuthorisationExpiredError, InvalidMonzoAPIResponseError

from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.exceptions import ConfigEntryAuthFailed, HomeAssistantError
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .api import AuthenticatedMonzoAPI
Expand Down Expand Up @@ -45,5 +46,10 @@ async def _async_update_data(self) -> MonzoData:
pots = await self.api.user_account.pots()
except AuthorisationExpiredError as err:
raise ConfigEntryAuthFailed from err
except InvalidMonzoAPIResponseError as err:
message = "Invalid Monzo API response."
if err.missing_key:
message += f"\nMissing key: {err.missing_key} Response:\n{pformat(err.response)}"
raise HomeAssistantError(message) from err

Check warning on line 53 in homeassistant/components/monzo/coordinator.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/monzo/coordinator.py#L50-L53

Added lines #L50 - L53 were not covered by tests

return MonzoData(accounts, pots)

0 comments on commit 60b1d71

Please sign in to comment.