From ab2f5bab5dfc9011e28c7f2675474d76162b9bcd Mon Sep 17 00:00:00 2001 From: Josef Zweck Date: Mon, 24 Aug 2026 19:20:36 +0200 Subject: [PATCH] Allow ConfigEntryNotReady as error in coordinator async_setup (#180011) --- homeassistant/helpers/update_coordinator.py | 9 ++++++ tests/helpers/test_update_coordinator.py | 31 +++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/homeassistant/helpers/update_coordinator.py b/homeassistant/helpers/update_coordinator.py index e8b47af35f62..a23f28d12bc8 100644 --- a/homeassistant/helpers/update_coordinator.py +++ b/homeassistant/helpers/update_coordinator.py @@ -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: diff --git a/tests/helpers/test_update_coordinator.py b/tests/helpers/test_update_coordinator.py index aedeb1ae6cbd..9c881d56b8b0 100644 --- a/tests/helpers/test_update_coordinator.py +++ b/tests/helpers/test_update_coordinator.py @@ -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()