Deprecate hass.helpers
(#114484)
* Deprecate hass.helpers * Patch * Patch _REPORTED_INTEGRATIONS set in test * Fix test * Update version
This commit is contained in:
parent
f2f24a5d35
commit
d5da0a053b
2 changed files with 45 additions and 0 deletions
|
@ -1550,6 +1550,20 @@ class Helpers:
|
|||
def __getattr__(self, helper_name: str) -> ModuleWrapper:
|
||||
"""Fetch a helper."""
|
||||
helper = importlib.import_module(f"homeassistant.helpers.{helper_name}")
|
||||
|
||||
# Local import to avoid circular dependencies
|
||||
from .helpers.frame import report # pylint: disable=import-outside-toplevel
|
||||
|
||||
report(
|
||||
(
|
||||
f"accesses hass.helpers.{helper_name}."
|
||||
" This is deprecated and will stop working in Home Assistant 2024.11, it"
|
||||
f" should be updated to import functions used from {helper_name} directly"
|
||||
),
|
||||
error_if_core=False,
|
||||
log_custom_component_only=True,
|
||||
)
|
||||
|
||||
wrapped = ModuleWrapper(self._hass, helper)
|
||||
setattr(self, helper_name, wrapped)
|
||||
return wrapped
|
||||
|
|
|
@ -1779,3 +1779,34 @@ async def test_has_services(hass: HomeAssistant, enable_custom_integrations) ->
|
|||
assert integration.has_services is False
|
||||
integration = await loader.async_get_integration(hass, "test_with_services")
|
||||
assert integration.has_services is True
|
||||
|
||||
|
||||
async def test_hass_helpers_use_reported(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock
|
||||
) -> None:
|
||||
"""Test that use of hass.components is reported."""
|
||||
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.object(frame, "_REPORTED_INTEGRATIONS", new=set()),
|
||||
patch(
|
||||
"homeassistant.helpers.frame.get_integration_frame",
|
||||
return_value=integration_frame,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.helpers.aiohttp_client.async_get_clientsession",
|
||||
return_value=None,
|
||||
),
|
||||
):
|
||||
hass.helpers.aiohttp_client.async_get_clientsession()
|
||||
|
||||
assert (
|
||||
"Detected that custom integration 'test_integration_frame' "
|
||||
"accesses hass.helpers.aiohttp_client. This is deprecated"
|
||||
) in caplog.text
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue