mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 06:05:26 +01:00
Follow through with deprecation in async_config_entry_first_refresh (#158775)
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user