From 63391717e72159e25e3d89796780eead47e1fdfc Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:24:47 +0200 Subject: [PATCH] Replace ValueError with deprecation in data update coordinator (#128082) * Replace ValueError with deprecation in data update coordinator * Rephrase --- homeassistant/helpers/update_coordinator.py | 9 +++++++-- tests/helpers/test_update_coordinator.py | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/update_coordinator.py b/homeassistant/helpers/update_coordinator.py index e2739bbdca9..0066def922f 100644 --- a/homeassistant/helpers/update_coordinator.py +++ b/homeassistant/helpers/update_coordinator.py @@ -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( diff --git a/tests/helpers/test_update_coordinator.py b/tests/helpers/test_update_coordinator.py index 48a2fe416d1..15043dc2c76 100644 --- a/tests/helpers/test_update_coordinator.py +++ b/tests/helpers/test_update_coordinator.py @@ -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()