Use breaks_in_ha_version in report_usage (#131137)

* Use breaks_in_ha_version in report_usage

* Revert behavior change
This commit is contained in:
epenet 2024-11-23 18:58:24 +01:00 committed by GitHub
parent 50013cf5c7
commit c7485b94d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 55 additions and 70 deletions

View File

@ -509,10 +509,10 @@ class HomeAssistantHTTP:
"calls hass.http.register_static_path which is deprecated because " "calls hass.http.register_static_path which is deprecated because "
"it does blocking I/O in the event loop, instead " "it does blocking I/O in the event loop, instead "
"call `await hass.http.async_register_static_paths(" "call `await hass.http.async_register_static_paths("
f'[StaticPathConfig("{url_path}", "{path}", {cache_headers})])`; ' f'[StaticPathConfig("{url_path}", "{path}", {cache_headers})])`',
"This function will be removed in 2025.7",
exclude_integrations={"http"}, exclude_integrations={"http"},
core_behavior=frame.ReportBehavior.LOG, core_behavior=frame.ReportBehavior.LOG,
breaks_in_ha_version="2025.7",
) )
configs = [StaticPathConfig(url_path, path, cache_headers)] configs = [StaticPathConfig(url_path, path, cache_headers)]
resources = self._make_static_resources(configs) resources = self._make_static_resources(configs)

View File

@ -657,11 +657,11 @@ class HomeAssistant:
from .helpers import frame # pylint: disable=import-outside-toplevel from .helpers import frame # pylint: disable=import-outside-toplevel
frame.report_usage( frame.report_usage(
"calls `async_add_job`, which is deprecated and will be removed in Home " "calls `async_add_job`, which should be reviewed against "
"Assistant 2025.4; Please review "
"https://developers.home-assistant.io/blog/2024/03/13/deprecate_add_run_job" "https://developers.home-assistant.io/blog/2024/03/13/deprecate_add_run_job"
" for replacement options", " for replacement options",
core_behavior=frame.ReportBehavior.LOG, core_behavior=frame.ReportBehavior.LOG,
breaks_in_ha_version="2025.4",
) )
if target is None: if target is None:
@ -713,11 +713,11 @@ class HomeAssistant:
from .helpers import frame # pylint: disable=import-outside-toplevel from .helpers import frame # pylint: disable=import-outside-toplevel
frame.report_usage( frame.report_usage(
"calls `async_add_hass_job`, which is deprecated and will be removed in Home " "calls `async_add_hass_job`, which should be reviewed against "
"Assistant 2025.5; Please review "
"https://developers.home-assistant.io/blog/2024/04/07/deprecate_add_hass_job" "https://developers.home-assistant.io/blog/2024/04/07/deprecate_add_hass_job"
" for replacement options", " for replacement options",
core_behavior=frame.ReportBehavior.LOG, core_behavior=frame.ReportBehavior.LOG,
breaks_in_ha_version="2025.5",
) )
return self._async_add_hass_job(hassjob, *args, background=background) return self._async_add_hass_job(hassjob, *args, background=background)
@ -987,11 +987,11 @@ class HomeAssistant:
from .helpers import frame # pylint: disable=import-outside-toplevel from .helpers import frame # pylint: disable=import-outside-toplevel
frame.report_usage( frame.report_usage(
"calls `async_run_job`, which is deprecated and will be removed in Home " "calls `async_run_job`, which should be reviewed against "
"Assistant 2025.4; Please review "
"https://developers.home-assistant.io/blog/2024/03/13/deprecate_add_run_job" "https://developers.home-assistant.io/blog/2024/03/13/deprecate_add_run_job"
" for replacement options", " for replacement options",
core_behavior=frame.ReportBehavior.LOG, core_behavior=frame.ReportBehavior.LOG,
breaks_in_ha_version="2025.4",
) )
if asyncio.iscoroutine(target): if asyncio.iscoroutine(target):
@ -1636,9 +1636,9 @@ class EventBus:
from .helpers import frame # pylint: disable=import-outside-toplevel from .helpers import frame # pylint: disable=import-outside-toplevel
frame.report_usage( frame.report_usage(
"calls `async_listen` with run_immediately, which is" "calls `async_listen` with run_immediately",
" deprecated and will be removed in Home Assistant 2025.5",
core_behavior=frame.ReportBehavior.LOG, 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): if event_filter is not None and not is_callback_check_partial(event_filter):
@ -1706,9 +1706,9 @@ class EventBus:
from .helpers import frame # pylint: disable=import-outside-toplevel from .helpers import frame # pylint: disable=import-outside-toplevel
frame.report_usage( frame.report_usage(
"calls `async_listen_once` with run_immediately, which is " "calls `async_listen_once` with run_immediately",
"deprecated and will be removed in Home Assistant 2025.5",
core_behavior=frame.ReportBehavior.LOG, core_behavior=frame.ReportBehavior.LOG,
breaks_in_ha_version="2025.5",
) )
one_time_listener: _OneTimeListener[_DataT] = _OneTimeListener( one_time_listener: _OneTimeListener[_DataT] = _OneTimeListener(

View File

@ -696,10 +696,10 @@ class Config:
It will be removed in Home Assistant 2025.6. It will be removed in Home Assistant 2025.6.
""" """
report_usage( report_usage(
"set the time zone using set_time_zone instead of async_set_time_zone" "sets the time zone using set_time_zone instead of async_set_time_zone",
" which will stop working in Home Assistant 2025.6",
core_integration_behavior=ReportBehavior.ERROR, core_integration_behavior=ReportBehavior.ERROR,
custom_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): if time_zone := dt_util.get_time_zone(time_zone_str):
self.time_zone = time_zone_str self.time_zone = time_zone_str

View File

@ -531,11 +531,9 @@ class FlowManager(abc.ABC, Generic[_FlowContextT, _FlowResultT, _HandlerT]):
if not isinstance(result["type"], FlowResultType): if not isinstance(result["type"], FlowResultType):
result["type"] = FlowResultType(result["type"]) # type: ignore[unreachable] result["type"] = FlowResultType(result["type"]) # type: ignore[unreachable]
report_usage( report_usage(
( "does not use FlowResultType enum for data entry flow result type",
"does not use FlowResultType enum for data entry flow result type. "
"This is deprecated and will stop working in Home Assistant 2025.1"
),
core_behavior=ReportBehavior.LOG, core_behavior=ReportBehavior.LOG,
breaks_in_ha_version="2025.1",
) )
if ( if (

View File

@ -996,15 +996,10 @@ class TrackTemplateResultInfo:
if track_template_.template.hass: if track_template_.template.hass:
continue continue
# pylint: disable-next=import-outside-toplevel frame.report_usage(
from .frame import ReportBehavior, report_usage "calls async_track_template_result with template without hass",
core_behavior=frame.ReportBehavior.LOG,
report_usage( breaks_in_ha_version="2025.10",
(
"calls async_track_template_result with template without hass, "
"which will stop working in HA Core 2025.10"
),
core_behavior=ReportBehavior.LOG,
) )
track_template_.template.hass = hass track_template_.template.hass = hass

View File

@ -1280,11 +1280,9 @@ def async_register_entity_service(
from .frame import ReportBehavior, report_usage from .frame import ReportBehavior, report_usage
report_usage( report_usage(
( "registers an entity service with a non entity service schema",
"registers an entity service with a non entity service schema "
"which will stop working in HA Core 2025.9"
),
core_behavior=ReportBehavior.LOG, core_behavior=ReportBehavior.LOG,
breaks_in_ha_version="2025.9",
) )
service_func: str | HassJob[..., Any] service_func: str | HassJob[..., Any]

View File

@ -522,11 +522,9 @@ class Template:
if not hass: if not hass:
report_usage( report_usage(
( "creates a template object without passing hass",
"creates a template object without passing hass, "
"which will stop working in HA Core 2025.10"
),
core_behavior=ReportBehavior.LOG, core_behavior=ReportBehavior.LOG,
breaks_in_ha_version="2025.10",
) )
self.template: str = template.strip() self.template: str = template.strip()

View File

@ -289,8 +289,8 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
if self.config_entry is None: if self.config_entry is None:
report_usage( report_usage(
"uses `async_config_entry_first_refresh`, which is only supported " "uses `async_config_entry_first_refresh`, which is only supported "
"for coordinators with a config entry and will stop working in " "for coordinators with a config entry",
"Home Assistant 2025.11" breaks_in_ha_version="2025.11",
) )
elif ( elif (
self.config_entry.state self.config_entry.state
@ -299,8 +299,8 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
report_usage( report_usage(
"uses `async_config_entry_first_refresh`, which is only supported " "uses `async_config_entry_first_refresh`, which is only supported "
f"when entry state is {config_entries.ConfigEntryState.SETUP_IN_PROGRESS}, " f"when entry state is {config_entries.ConfigEntryState.SETUP_IN_PROGRESS}, "
f"but it is in state {self.config_entry.state}, " f"but it is in state {self.config_entry.state}",
"This will stop working in Home Assistant 2025.11", breaks_in_ha_version="2025.11",
) )
if await self.__wrap_async_setup(): if await self.__wrap_async_setup():
await self._async_refresh( await self._async_refresh(

View File

@ -1560,14 +1560,12 @@ class Components:
from .helpers.frame import ReportBehavior, report_usage from .helpers.frame import ReportBehavior, report_usage
report_usage( report_usage(
( f"accesses hass.components.{comp_name}, which"
f"accesses hass.components.{comp_name}." f" should be updated to import functions used from {comp_name} directly",
" 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"
),
core_behavior=ReportBehavior.IGNORE, core_behavior=ReportBehavior.IGNORE,
core_integration_behavior=ReportBehavior.IGNORE, core_integration_behavior=ReportBehavior.IGNORE,
custom_integration_behavior=ReportBehavior.LOG, custom_integration_behavior=ReportBehavior.LOG,
breaks_in_ha_version="2025.3",
) )
wrapped = ModuleWrapper(self._hass, component) wrapped = ModuleWrapper(self._hass, component)
@ -1592,13 +1590,13 @@ class Helpers:
report_usage( report_usage(
( (
f"accesses hass.helpers.{helper_name}." f"accesses hass.helpers.{helper_name}, which"
" This is deprecated and will stop working in Home Assistant 2025.5, it"
f" should be updated to import functions used from {helper_name} directly" f" should be updated to import functions used from {helper_name} directly"
), ),
core_behavior=ReportBehavior.IGNORE, core_behavior=ReportBehavior.IGNORE,
core_integration_behavior=ReportBehavior.IGNORE, core_integration_behavior=ReportBehavior.IGNORE,
custom_integration_behavior=ReportBehavior.LOG, custom_integration_behavior=ReportBehavior.LOG,
breaks_in_ha_version="2025.5",
) )
wrapped = ModuleWrapper(self._hass, helper) wrapped = ModuleWrapper(self._hass, helper)

View File

@ -4946,7 +4946,8 @@ async def test_async_track_template_no_hass_deprecated(
"""Test async_track_template with a template without hass is deprecated.""" """Test async_track_template with a template without hass is deprecated."""
message = ( message = (
"Detected code that calls async_track_template_result with template without " "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) 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.""" """Test async_track_template_result with a template without hass is deprecated."""
message = ( message = (
"Detected code that calls async_track_template_result with template without " "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( async_track_template_result(

View File

@ -628,8 +628,7 @@ async def test_async_config_entry_first_refresh_invalid_state(
RuntimeError, RuntimeError,
match="Detected code that uses `async_config_entry_first_refresh`, which " match="Detected code that uses `async_config_entry_first_refresh`, which "
"is only supported when entry state is ConfigEntryState.SETUP_IN_PROGRESS, " "is only supported when entry state is ConfigEntryState.SETUP_IN_PROGRESS, "
"but it is in state ConfigEntryState.NOT_LOADED. This will stop working " "but it is in state ConfigEntryState.NOT_LOADED. Please report this issue",
"in Home Assistant 2025.11. Please report this issue",
): ):
await crd.async_config_entry_first_refresh() await crd.async_config_entry_first_refresh()
@ -653,8 +652,9 @@ async def test_async_config_entry_first_refresh_invalid_state_in_integration(
assert ( assert (
"Detected that integration 'hue' uses `async_config_entry_first_refresh`, which " "Detected that integration 'hue' uses `async_config_entry_first_refresh`, which "
"is only supported when entry state is ConfigEntryState.SETUP_IN_PROGRESS, " "is only supported when entry state is ConfigEntryState.SETUP_IN_PROGRESS, "
"but it is in state ConfigEntryState.NOT_LOADED, This will stop working " "but it is in state ConfigEntryState.NOT_LOADED at "
"in Home Assistant 2025.11" "homeassistant/components/hue/light.py, line 23: self.light.is_on. "
"This will stop working in Home Assistant 2025.11"
) in caplog.text ) in caplog.text
@ -665,8 +665,8 @@ async def test_async_config_entry_first_refresh_no_entry(hass: HomeAssistant) ->
with pytest.raises( with pytest.raises(
RuntimeError, RuntimeError,
match="Detected code that uses `async_config_entry_first_refresh`, " match="Detected code that uses `async_config_entry_first_refresh`, "
"which is only supported for coordinators with a config entry and will " "which is only supported for coordinators with a config entry. "
"stop working in Home Assistant 2025.11. Please report this issue", "Please report this issue",
): ):
await crd.async_config_entry_first_refresh() await crd.async_config_entry_first_refresh()

View File

@ -3040,10 +3040,9 @@ async def test_async_run_job_deprecated(
hass.async_run_job(_test) hass.async_run_job(_test)
assert ( assert (
"Detected code that calls `async_run_job`, which is deprecated " "Detected code that calls `async_run_job`, which should be reviewed against "
"and will be removed in Home Assistant 2025.4; Please review "
"https://developers.home-assistant.io/blog/2024/03/13/deprecate_add_run_job" "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 ) in caplog.text
@ -3057,10 +3056,9 @@ async def test_async_add_job_deprecated(
hass.async_add_job(_test) hass.async_add_job(_test)
assert ( assert (
"Detected code that calls `async_add_job`, which is deprecated " "Detected code that calls `async_add_job`, which should be reviewed against "
"and will be removed in Home Assistant 2025.4; Please review "
"https://developers.home-assistant.io/blog/2024/03/13/deprecate_add_run_job" "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 ) in caplog.text
@ -3074,10 +3072,9 @@ async def test_async_add_hass_job_deprecated(
hass.async_add_hass_job(HassJob(_test)) hass.async_add_hass_job(HassJob(_test))
assert ( assert (
"Detected code that calls `async_add_hass_job`, which is deprecated " "Detected code that calls `async_add_hass_job`, which should be reviewed against "
"and will be removed in Home Assistant 2025.5; Please review "
"https://developers.home-assistant.io/blog/2024/04/07/deprecate_add_hass_job" "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 ) in caplog.text
@ -3245,8 +3242,8 @@ async def test_async_listen_with_run_immediately_deprecated(
func = getattr(hass.bus, method) func = getattr(hass.bus, method)
func(EVENT_HOMEASSISTANT_START, _test, run_immediately=run_immediately) func(EVENT_HOMEASSISTANT_START, _test, run_immediately=run_immediately)
assert ( assert (
f"Detected code that calls `{method}` with run_immediately, which is " f"Detected code that calls `{method}` with run_immediately. "
"deprecated and will be removed in Home Assistant 2025.5." "This will stop working in Home Assistant 2025.5"
) in caplog.text ) in caplog.text

View File

@ -1075,9 +1075,8 @@ async def test_set_time_zone_deprecated(hass: HomeAssistant) -> None:
with pytest.raises( with pytest.raises(
RuntimeError, RuntimeError,
match=re.escape( match=re.escape(
"Detected code that set the time zone using set_time_zone instead of " "Detected code that sets the time zone using set_time_zone instead of "
"async_set_time_zone which will stop working in Home Assistant 2025.6. " "async_set_time_zone. Please report this issue"
"Please report this issue",
), ),
): ):
await hass.config.set_time_zone("America/New_York") await hass.config.set_time_zone("America/New_York")

View File

@ -1327,7 +1327,7 @@ async def test_hass_components_use_reported(
reported = ( reported = (
"Detected that custom integration 'test_integration_frame'" "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 ) in caplog.text
assert reported == expected assert reported == expected
@ -2023,7 +2023,7 @@ async def test_hass_helpers_use_reported(
reported = ( reported = (
"Detected that custom integration 'test_integration_frame' " "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 ) in caplog.text
assert reported == expected assert reported == expected