Skip to content

Commit

Permalink
Use breaks_in_ha_version in report_usage (#131137)
Browse files Browse the repository at this point in the history
* Use breaks_in_ha_version in report_usage

* Revert behavior change
  • Loading branch information
epenet authored Nov 23, 2024
1 parent 50013cf commit c7485b9
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 70 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/core_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/data_entry_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
13 changes: 4 additions & 9 deletions homeassistant/helpers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions homeassistant/helpers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/helpers/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/helpers/update_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
12 changes: 5 additions & 7 deletions homeassistant/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions tests/helpers/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions tests/helpers/test_update_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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


Expand All @@ -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()

Expand Down
19 changes: 8 additions & 11 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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


Expand All @@ -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


Expand Down Expand Up @@ -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


Expand Down
5 changes: 2 additions & 3 deletions tests/test_core_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
4 changes: 2 additions & 2 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit c7485b9

Please sign in to comment.