mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 01:11:51 -04:00
Allow ConfigEntryNotReady as error in coordinator async_setup (#180011)
This commit is contained in:
@@ -378,6 +378,7 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
|
||||
requests.exceptions.RequestException,
|
||||
urllib.error.URLError,
|
||||
UpdateFailed,
|
||||
ConfigEntryNotReady,
|
||||
) as err:
|
||||
self.last_exception = err
|
||||
|
||||
@@ -507,6 +508,14 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
|
||||
self.logger.debug("Full error:", exc_info=True)
|
||||
self.last_update_success = False
|
||||
|
||||
except ConfigEntryNotReady as err:
|
||||
self.last_exception = err
|
||||
if self.last_update_success:
|
||||
if log_failures:
|
||||
self.logger.error("Error fetching %s data: %s", self.name, err)
|
||||
self.logger.debug("Full error:", exc_info=True)
|
||||
self.last_update_success = False
|
||||
|
||||
except ConfigEntryError as err:
|
||||
self.last_exception = err
|
||||
if self.last_update_success:
|
||||
|
||||
@@ -57,6 +57,11 @@ KNOWN_ERRORS: list[tuple[Exception, type[Exception], str]] = [
|
||||
update_coordinator.UpdateFailed,
|
||||
"Error fetching test data",
|
||||
),
|
||||
(
|
||||
ConfigEntryNotReady(),
|
||||
ConfigEntryNotReady,
|
||||
"Error fetching test data",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -782,6 +787,32 @@ async def test_async_config_entry_first_refresh_failure_passed_through(
|
||||
assert err_msg[2] not in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"method",
|
||||
["update_method", "setup_method"],
|
||||
)
|
||||
async def test_async_config_entry_first_refresh_not_ready(
|
||||
hass: HomeAssistant,
|
||||
method: str,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test ConfigEntryNotReady is treated as a recoverable error."""
|
||||
|
||||
entry = MockConfigEntry()
|
||||
entry._async_set_state(
|
||||
hass, config_entries.ConfigEntryState.SETUP_IN_PROGRESS, None
|
||||
)
|
||||
crd = get_crd(hass, DEFAULT_UPDATE_INTERVAL, entry)
|
||||
setattr(crd, method, AsyncMock(side_effect=ConfigEntryNotReady("Not ready")))
|
||||
|
||||
with pytest.raises(ConfigEntryNotReady):
|
||||
await crd.async_config_entry_first_refresh()
|
||||
|
||||
assert crd.last_update_success is False
|
||||
assert isinstance(crd.last_exception, ConfigEntryNotReady)
|
||||
assert "Unexpected error fetching test data" not in caplog.text
|
||||
|
||||
|
||||
async def test_async_config_entry_first_refresh_success(hass: HomeAssistant) -> None:
|
||||
"""Test first refresh successfully."""
|
||||
entry = MockConfigEntry()
|
||||
|
||||
Reference in New Issue
Block a user