Follow through with deprecation in async_config_entry_first_refresh (#158775)

This commit is contained in:
Josef Zweck
2025-12-21 07:56:35 +01:00
committed by GitHub
parent c95416cb48
commit 28dc32d5dc
2 changed files with 17 additions and 20 deletions

View File

@@ -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(

View File

@@ -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: