Replace ValueError with deprecation in data update coordinator (#128082)

* Replace ValueError with deprecation in data update coordinator

* Rephrase
This commit is contained in:
epenet 2024-10-11 17:24:47 +02:00 committed by GitHub
parent 554629f37a
commit 63391717e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

@ -29,6 +29,7 @@ from homeassistant.util.dt import utcnow
from . import entity, event
from .debounce import Debouncer
from .frame import report
from .typing import UNDEFINED, UndefinedType
REQUEST_REFRESH_DEFAULT_COOLDOWN = 10
@ -285,8 +286,12 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
to ensure that multiple retries do not cause log spam.
"""
if self.config_entry is None:
raise ValueError(
"This method is only supported for coordinators with a config entry"
report(
"uses `async_config_entry_first_refresh`, which is only supported "
"for coordinators with a config entry and will stop working in "
"Home Assistant 2025.11",
error_if_core=True,
error_if_integration=False,
)
if await self.__wrap_async_setup():
await self._async_refresh(

View File

@ -613,8 +613,10 @@ async def test_async_config_entry_first_refresh_no_entry(hass: HomeAssistant) ->
crd = get_crd(hass, DEFAULT_UPDATE_INTERVAL, None)
crd.setup_method = AsyncMock()
with pytest.raises(
ValueError,
match="This method is only supported for coordinators with a config entry",
RuntimeError,
match="Detected code that uses `async_config_entry_first_refresh`, "
"which is only supported for coordinators with a config entry and will "
"stop working in Home Assistant 2025.11. Please report this issue.",
):
await crd.async_config_entry_first_refresh()