Skip to content

Commit

Permalink
Log warning only when hass.components is used
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede committed Feb 27, 2024
1 parent 48eabf7 commit 0673c98
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 42 deletions.
12 changes: 0 additions & 12 deletions homeassistant/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,18 +1285,6 @@ def bind_hass(func: _CallableT) -> _CallableT:
The use of this decorator is discouraged, and it should not be used
for new functions.
"""
from .helpers.frame import report # pylint: disable=import-outside-toplevel

report(
(
"uses @bind_hass decorator."
" This is deprecated and will stop working in Home Assistant 2024.9, it"
" should be updated to pass hass object as first argument"
),
error_if_core=False,
log_custom_component_only=True,
)

setattr(func, "__bind_hass", True)
return func

Expand Down
34 changes: 4 additions & 30 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,39 +1005,13 @@ async def test_config_folder_not_in_path(hass):
import tests.testing_config.check_config_not_in_path # noqa: F401


async def test_bind_hass_use_reported(
caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock
) -> None:
"""Test that use of @bind_hass is reported."""
from homeassistant.loader import bind_hass

integration_frame = frame.IntegrationFrame(
custom_integration=True,
frame=mock_integration_frame,
integration="test_integration_frame",
module="custom_components.test_integration_frame",
relative_filename="custom_components/test_integration_frame/__init__.py",
)

with patch(
"homeassistant.helpers.frame.get_integration_frame",
return_value=integration_frame,
):

@bind_hass
def _test(hass: HomeAssistant):
pass

assert (
"Detected that custom integration 'test_integration_frame'"
" uses @bind_hass decorator. This is deprecated"
) in caplog.text


async def test_hass_components_use_reported(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock
) -> None:
"""Test that use of hass.components is reported."""
mock_integration_frame.filename = (
"/home/paulus/homeassistant/custom_components/demo/light.py"
)
integration_frame = frame.IntegrationFrame(
custom_integration=True,
frame=mock_integration_frame,
Expand All @@ -1053,7 +1027,7 @@ async def test_hass_components_use_reported(
"homeassistant.components.http.start_http_server_and_save_config",
return_value=None,
):
await hass.components.http.start_http_server_and_save_config(hass, [], None)
hass.components.http.start_http_server_and_save_config(hass, [], None)

assert (
"Detected that custom integration 'test_integration_frame'"
Expand Down

0 comments on commit 0673c98

Please sign in to comment.