Skip to content

Commit

Permalink
Change error again
Browse files Browse the repository at this point in the history
  • Loading branch information
Lash-L committed Nov 11, 2024
1 parent b8acc4a commit 7b746c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions custom_components/bermuda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: BermudaConfigEntry):
coordinator = BermudaDataUpdateCoordinator(hass, entry)
entry.runtime_data = BermudaData(coordinator)

await coordinator.async_refresh()

if not coordinator.last_update_success:
async def on_failure():
_LOGGER.debug("Coordinator last update failed, rasing ConfigEntryNotReady")
await coordinator.stop_purging()
raise ConfigEntryNotReady

try:
await coordinator.async_refresh()
except Exception as ex: # noqa: BLE001
_LOGGER.exception(ex)
await on_failure()
if not coordinator.last_update_success:
await on_failure()

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

entry.async_on_unload(entry.add_update_listener(async_reload_entry))
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def error_get_data_fixture():
"""Simulate error when retrieving data from API."""
with patch(
"custom_components.bermuda.BermudaDataUpdateCoordinator.async_refresh",
side_effect=UpdateFailed,
side_effect=Exception,
):
yield

Expand Down

0 comments on commit 7b746c9

Please sign in to comment.