From c7485b94d5b9ff6a33fd185a13aaf8bc5772b866 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sat, 23 Nov 2024 18:58:24 +0100 Subject: [PATCH] Use breaks_in_ha_version in report_usage (#131137) * Use breaks_in_ha_version in report_usage * Revert behavior change --- homeassistant/components/http/__init__.py | 4 ++-- homeassistant/core.py | 20 ++++++++++---------- homeassistant/core_config.py | 4 ++-- homeassistant/data_entry_flow.py | 6 ++---- homeassistant/helpers/event.py | 13 ++++--------- homeassistant/helpers/service.py | 6 ++---- homeassistant/helpers/template.py | 6 ++---- homeassistant/helpers/update_coordinator.py | 8 ++++---- homeassistant/loader.py | 12 +++++------- tests/helpers/test_event.py | 6 ++++-- tests/helpers/test_update_coordinator.py | 12 ++++++------ tests/test_core.py | 19 ++++++++----------- tests/test_core_config.py | 5 ++--- tests/test_loader.py | 4 ++-- 14 files changed, 55 insertions(+), 70 deletions(-) diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index c9c75b0c04e1c4..3b18b44862a998 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -509,10 +509,10 @@ def register_static_path( "calls hass.http.register_static_path which is deprecated because " "it does blocking I/O in the event loop, instead " "call `await hass.http.async_register_static_paths(" - f'[StaticPathConfig("{url_path}", "{path}", {cache_headers})])`; ' - "This function will be removed in 2025.7", + f'[StaticPathConfig("{url_path}", "{path}", {cache_headers})])`', exclude_integrations={"http"}, core_behavior=frame.ReportBehavior.LOG, + breaks_in_ha_version="2025.7", ) configs = [StaticPathConfig(url_path, path, cache_headers)] resources = self._make_static_resources(configs) diff --git a/homeassistant/core.py b/homeassistant/core.py index cdfb5570b4437b..f4c819c1262c37 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -657,11 +657,11 @@ def async_add_job[_R, *_Ts]( from .helpers import frame # pylint: disable=import-outside-toplevel frame.report_usage( - "calls `async_add_job`, which is deprecated and will be removed in Home " - "Assistant 2025.4; Please review " + "calls `async_add_job`, which should be reviewed against " "https://developers.home-assistant.io/blog/2024/03/13/deprecate_add_run_job" " for replacement options", core_behavior=frame.ReportBehavior.LOG, + breaks_in_ha_version="2025.4", ) if target is None: @@ -713,11 +713,11 @@ def async_add_hass_job[_R]( from .helpers import frame # pylint: disable=import-outside-toplevel frame.report_usage( - "calls `async_add_hass_job`, which is deprecated and will be removed in Home " - "Assistant 2025.5; Please review " + "calls `async_add_hass_job`, which should be reviewed against " "https://developers.home-assistant.io/blog/2024/04/07/deprecate_add_hass_job" " for replacement options", core_behavior=frame.ReportBehavior.LOG, + breaks_in_ha_version="2025.5", ) return self._async_add_hass_job(hassjob, *args, background=background) @@ -987,11 +987,11 @@ def async_run_job[_R, *_Ts]( from .helpers import frame # pylint: disable=import-outside-toplevel frame.report_usage( - "calls `async_run_job`, which is deprecated and will be removed in Home " - "Assistant 2025.4; Please review " + "calls `async_run_job`, which should be reviewed against " "https://developers.home-assistant.io/blog/2024/03/13/deprecate_add_run_job" " for replacement options", core_behavior=frame.ReportBehavior.LOG, + breaks_in_ha_version="2025.4", ) if asyncio.iscoroutine(target): @@ -1636,9 +1636,9 @@ def async_listen( from .helpers import frame # pylint: disable=import-outside-toplevel frame.report_usage( - "calls `async_listen` with run_immediately, which is" - " deprecated and will be removed in Home Assistant 2025.5", + "calls `async_listen` with run_immediately", core_behavior=frame.ReportBehavior.LOG, + breaks_in_ha_version="2025.5", ) if event_filter is not None and not is_callback_check_partial(event_filter): @@ -1706,9 +1706,9 @@ def async_listen_once( from .helpers import frame # pylint: disable=import-outside-toplevel frame.report_usage( - "calls `async_listen_once` with run_immediately, which is " - "deprecated and will be removed in Home Assistant 2025.5", + "calls `async_listen_once` with run_immediately", core_behavior=frame.ReportBehavior.LOG, + breaks_in_ha_version="2025.5", ) one_time_listener: _OneTimeListener[_DataT] = _OneTimeListener( diff --git a/homeassistant/core_config.py b/homeassistant/core_config.py index 5c773c57bc4399..430a882ecb930e 100644 --- a/homeassistant/core_config.py +++ b/homeassistant/core_config.py @@ -696,10 +696,10 @@ def set_time_zone(self, time_zone_str: str) -> None: It will be removed in Home Assistant 2025.6. """ report_usage( - "set the time zone using set_time_zone instead of async_set_time_zone" - " which will stop working in Home Assistant 2025.6", + "sets the time zone using set_time_zone instead of async_set_time_zone", core_integration_behavior=ReportBehavior.ERROR, custom_integration_behavior=ReportBehavior.ERROR, + breaks_in_ha_version="2025.6", ) if time_zone := dt_util.get_time_zone(time_zone_str): self.time_zone = time_zone_str diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 63baca56aebd3d..338b5f3992f4b6 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -531,11 +531,9 @@ async def _async_handle_step( if not isinstance(result["type"], FlowResultType): result["type"] = FlowResultType(result["type"]) # type: ignore[unreachable] report_usage( - ( - "does not use FlowResultType enum for data entry flow result type. " - "This is deprecated and will stop working in Home Assistant 2025.1" - ), + "does not use FlowResultType enum for data entry flow result type", core_behavior=ReportBehavior.LOG, + breaks_in_ha_version="2025.1", ) if ( diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index 779cd8d5108bd3..578132f358f10b 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -996,15 +996,10 @@ def __init__( if track_template_.template.hass: continue - # pylint: disable-next=import-outside-toplevel - from .frame import ReportBehavior, report_usage - - report_usage( - ( - "calls async_track_template_result with template without hass, " - "which will stop working in HA Core 2025.10" - ), - core_behavior=ReportBehavior.LOG, + frame.report_usage( + "calls async_track_template_result with template without hass", + core_behavior=frame.ReportBehavior.LOG, + breaks_in_ha_version="2025.10", ) track_template_.template.hass = hass diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index e3da52604cb7e9..31b2e8e8ac8cbe 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -1280,11 +1280,9 @@ def async_register_entity_service( from .frame import ReportBehavior, report_usage report_usage( - ( - "registers an entity service with a non entity service schema " - "which will stop working in HA Core 2025.9" - ), + "registers an entity service with a non entity service schema", core_behavior=ReportBehavior.LOG, + breaks_in_ha_version="2025.9", ) service_func: str | HassJob[..., Any] diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 2eab666bbd4de1..57587dc21d60de 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -522,11 +522,9 @@ def __init__(self, template: str, hass: HomeAssistant | None = None) -> None: if not hass: report_usage( - ( - "creates a template object without passing hass, " - "which will stop working in HA Core 2025.10" - ), + "creates a template object without passing hass", core_behavior=ReportBehavior.LOG, + breaks_in_ha_version="2025.10", ) self.template: str = template.strip() diff --git a/homeassistant/helpers/update_coordinator.py b/homeassistant/helpers/update_coordinator.py index 6c94fba65d68a4..6cc4584935e5f4 100644 --- a/homeassistant/helpers/update_coordinator.py +++ b/homeassistant/helpers/update_coordinator.py @@ -289,8 +289,8 @@ async def async_config_entry_first_refresh(self) -> None: if self.config_entry is None: report_usage( "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" + "for coordinators with a config entry", + breaks_in_ha_version="2025.11", ) elif ( self.config_entry.state @@ -299,8 +299,8 @@ async def async_config_entry_first_refresh(self) -> None: 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}, " - "This will stop working in Home Assistant 2025.11", + f"but it is in state {self.config_entry.state}", + breaks_in_ha_version="2025.11", ) if await self.__wrap_async_setup(): await self._async_refresh( diff --git a/homeassistant/loader.py b/homeassistant/loader.py index e63de0c80262a5..4313cd2d6e0cdf 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -1560,14 +1560,12 @@ def __getattr__(self, comp_name: str) -> ModuleWrapper: from .helpers.frame import ReportBehavior, report_usage report_usage( - ( - f"accesses hass.components.{comp_name}." - " This is deprecated and will stop working in Home Assistant 2025.3, it" - f" should be updated to import functions used from {comp_name} directly" - ), + f"accesses hass.components.{comp_name}, which" + f" should be updated to import functions used from {comp_name} directly", core_behavior=ReportBehavior.IGNORE, core_integration_behavior=ReportBehavior.IGNORE, custom_integration_behavior=ReportBehavior.LOG, + breaks_in_ha_version="2025.3", ) wrapped = ModuleWrapper(self._hass, component) @@ -1592,13 +1590,13 @@ def __getattr__(self, helper_name: str) -> ModuleWrapper: report_usage( ( - f"accesses hass.helpers.{helper_name}." - " This is deprecated and will stop working in Home Assistant 2025.5, it" + f"accesses hass.helpers.{helper_name}, which" f" should be updated to import functions used from {helper_name} directly" ), core_behavior=ReportBehavior.IGNORE, core_integration_behavior=ReportBehavior.IGNORE, custom_integration_behavior=ReportBehavior.LOG, + breaks_in_ha_version="2025.5", ) wrapped = ModuleWrapper(self._hass, helper) diff --git a/tests/helpers/test_event.py b/tests/helpers/test_event.py index f01fcf3dddad7a..a0014587cd0c5a 100644 --- a/tests/helpers/test_event.py +++ b/tests/helpers/test_event.py @@ -4946,7 +4946,8 @@ async def test_async_track_template_no_hass_deprecated( """Test async_track_template with a template without hass is deprecated.""" message = ( "Detected code that calls async_track_template_result with template without " - "hass, which will stop working in HA Core 2025.10. Please report this issue" + "hass. This will stop working in Home Assistant 2025.10, please " + "report this issue" ) async_track_template(hass, Template("blah"), lambda x, y, z: None) @@ -4964,7 +4965,8 @@ async def test_async_track_template_result_no_hass_deprecated( """Test async_track_template_result with a template without hass is deprecated.""" message = ( "Detected code that calls async_track_template_result with template without " - "hass, which will stop working in HA Core 2025.10. Please report this issue" + "hass. This will stop working in Home Assistant 2025.10, please " + "report this issue" ) async_track_template_result( diff --git a/tests/helpers/test_update_coordinator.py b/tests/helpers/test_update_coordinator.py index 70a95c6bec8488..539762a60ff720 100644 --- a/tests/helpers/test_update_coordinator.py +++ b/tests/helpers/test_update_coordinator.py @@ -628,8 +628,7 @@ async def test_async_config_entry_first_refresh_invalid_state( 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. This will stop working " - "in Home Assistant 2025.11. Please report this issue", + "but it is in state ConfigEntryState.NOT_LOADED. Please report this issue", ): await crd.async_config_entry_first_refresh() @@ -653,8 +652,9 @@ async def test_async_config_entry_first_refresh_invalid_state_in_integration( 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, This will stop working " - "in Home Assistant 2025.11" + "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 @@ -665,8 +665,8 @@ async def test_async_config_entry_first_refresh_no_entry(hass: HomeAssistant) -> with pytest.raises( 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", + "which is only supported for coordinators with a config entry. " + "Please report this issue", ): await crd.async_config_entry_first_refresh() diff --git a/tests/test_core.py b/tests/test_core.py index ed1aad15a2dc2d..df2d916e1668d2 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -3040,10 +3040,9 @@ async def _test() -> None: hass.async_run_job(_test) assert ( - "Detected code that calls `async_run_job`, which is deprecated " - "and will be removed in Home Assistant 2025.4; Please review " + "Detected code that calls `async_run_job`, which should be reviewed against " "https://developers.home-assistant.io/blog/2024/03/13/deprecate_add_run_job" - " for replacement options" + " for replacement options. This will stop working in Home Assistant 2025.4" ) in caplog.text @@ -3057,10 +3056,9 @@ async def _test() -> None: hass.async_add_job(_test) assert ( - "Detected code that calls `async_add_job`, which is deprecated " - "and will be removed in Home Assistant 2025.4; Please review " + "Detected code that calls `async_add_job`, which should be reviewed against " "https://developers.home-assistant.io/blog/2024/03/13/deprecate_add_run_job" - " for replacement options" + " for replacement options. This will stop working in Home Assistant 2025.4" ) in caplog.text @@ -3074,10 +3072,9 @@ async def _test() -> None: hass.async_add_hass_job(HassJob(_test)) assert ( - "Detected code that calls `async_add_hass_job`, which is deprecated " - "and will be removed in Home Assistant 2025.5; Please review " + "Detected code that calls `async_add_hass_job`, which should be reviewed against " "https://developers.home-assistant.io/blog/2024/04/07/deprecate_add_hass_job" - " for replacement options" + " for replacement options. This will stop working in Home Assistant 2025.5" ) in caplog.text @@ -3245,8 +3242,8 @@ async def _test(event: ha.Event): func = getattr(hass.bus, method) func(EVENT_HOMEASSISTANT_START, _test, run_immediately=run_immediately) assert ( - f"Detected code that calls `{method}` with run_immediately, which is " - "deprecated and will be removed in Home Assistant 2025.5." + f"Detected code that calls `{method}` with run_immediately. " + "This will stop working in Home Assistant 2025.5" ) in caplog.text diff --git a/tests/test_core_config.py b/tests/test_core_config.py index 4de7ab1e078499..cd77e3608dd6e7 100644 --- a/tests/test_core_config.py +++ b/tests/test_core_config.py @@ -1075,9 +1075,8 @@ async def test_set_time_zone_deprecated(hass: HomeAssistant) -> None: with pytest.raises( RuntimeError, match=re.escape( - "Detected code that set the time zone using set_time_zone instead of " - "async_set_time_zone which will stop working in Home Assistant 2025.6. " - "Please report this issue", + "Detected code that sets the time zone using set_time_zone instead of " + "async_set_time_zone. Please report this issue" ), ): await hass.config.set_time_zone("America/New_York") diff --git a/tests/test_loader.py b/tests/test_loader.py index 57d3d6fa832530..a39bd63ad0d137 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -1327,7 +1327,7 @@ async def test_hass_components_use_reported( reported = ( "Detected that custom integration 'test_integration_frame'" - " accesses hass.components.http. This is deprecated" + " accesses hass.components.http, which should be updated" ) in caplog.text assert reported == expected @@ -2023,7 +2023,7 @@ async def test_hass_helpers_use_reported( reported = ( "Detected that custom integration 'test_integration_frame' " - "accesses hass.helpers.aiohttp_client. This is deprecated" + "accesses hass.helpers.aiohttp_client, which should be updated" ) in caplog.text assert reported == expected