From 28dc32d5dc3eb504fabdd3c858f10a5daf6638ae Mon Sep 17 00:00:00 2001 From: Josef Zweck Date: Sun, 21 Dec 2025 07:56:35 +0100 Subject: [PATCH] Follow through with deprecation in async_config_entry_first_refresh (#158775) --- homeassistant/helpers/update_coordinator.py | 9 +++---- tests/helpers/test_update_coordinator.py | 28 ++++++++++----------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/homeassistant/helpers/update_coordinator.py b/homeassistant/helpers/update_coordinator.py index b0c21935aea..9c2915278ea 100644 --- a/homeassistant/helpers/update_coordinator.py +++ b/homeassistant/helpers/update_coordinator.py @@ -30,7 +30,6 @@ from homeassistant.util.dt import utcnow from . import entity, event from .debounce import Debouncer -from .frame import report_usage from .typing import UNDEFINED, UndefinedType REQUEST_REFRESH_DEFAULT_COOLDOWN = 10 @@ -333,11 +332,9 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]): self.config_entry.state is not config_entries.ConfigEntryState.SETUP_IN_PROGRESS ): - report_usage( - "uses `async_config_entry_first_refresh`, which is only supported " - f"when entry state is {config_entries.ConfigEntryState.SETUP_IN_PROGRESS}, " - f"but it is in state {self.config_entry.state}", - breaks_in_ha_version="2025.11", + raise ConfigEntryError( + f"`async_config_entry_first_refresh` called when config entry state is {self.config_entry.state}, " + f"but should only be called in state {config_entries.ConfigEntryState.SETUP_IN_PROGRESS}" ) if await self.__wrap_async_setup(): await self._async_refresh( diff --git a/tests/helpers/test_update_coordinator.py b/tests/helpers/test_update_coordinator.py index d177d8920a9..612b39293a2 100644 --- a/tests/helpers/test_update_coordinator.py +++ b/tests/helpers/test_update_coordinator.py @@ -720,13 +720,14 @@ async def test_async_config_entry_first_refresh_invalid_state( crd = get_crd(hass, DEFAULT_UPDATE_INTERVAL, entry) crd.setup_method = AsyncMock() with pytest.raises( - RuntimeError, - match="Detected code that uses `async_config_entry_first_refresh`, which " - "is only supported when entry state is ConfigEntryState.SETUP_IN_PROGRESS, " - "but it is in state ConfigEntryState.NOT_LOADED. Please report this issue", + config_entries.ConfigEntryError, + match="`async_config_entry_first_refresh` called when config entry state is ConfigEntryState.NOT_LOADED, " + "but should only be called in state ConfigEntryState.SETUP_IN_PROGRESS", ): await crd.async_config_entry_first_refresh() + assert entry.state is config_entries.ConfigEntryState.NOT_LOADED + assert crd.last_update_success is True crd.setup_method.assert_not_called() @@ -735,21 +736,20 @@ async def test_async_config_entry_first_refresh_invalid_state( async def test_async_config_entry_first_refresh_invalid_state_in_integration( hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: - """Test first refresh successfully, despite wrong state.""" + """Test first refresh fails, because of wrong state.""" entry = MockConfigEntry() crd = get_crd(hass, DEFAULT_UPDATE_INTERVAL, entry) crd.setup_method = AsyncMock() - await crd.async_config_entry_first_refresh() + with pytest.raises( + config_entries.ConfigEntryError, + match="`async_config_entry_first_refresh` called when config entry state is ConfigEntryState.NOT_LOADED, " + "but should only be called in state ConfigEntryState.SETUP_IN_PROGRESS", + ): + await crd.async_config_entry_first_refresh() + assert crd.last_update_success is True - crd.setup_method.assert_called() - assert ( - "Detected that integration 'hue' uses `async_config_entry_first_refresh`, which " - "is only supported when entry state is ConfigEntryState.SETUP_IN_PROGRESS, " - "but it is in state ConfigEntryState.NOT_LOADED at " - "homeassistant/components/hue/light.py, line 23: self.light.is_on. " - "This will stop working in Home Assistant 2025.11" - ) in caplog.text + crd.setup_method.assert_not_called() async def test_async_config_entry_first_refresh_no_entry(hass: HomeAssistant) -> None: