mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Remove deprecated hass.helpers
(#143514)
This commit is contained in:
parent
731d1ab796
commit
199a274c80
@ -427,9 +427,6 @@ class HomeAssistant:
|
|||||||
|
|
||||||
def __init__(self, config_dir: str) -> None:
|
def __init__(self, config_dir: str) -> None:
|
||||||
"""Initialize new Home Assistant object."""
|
"""Initialize new Home Assistant object."""
|
||||||
# pylint: disable-next=import-outside-toplevel
|
|
||||||
from . import loader
|
|
||||||
|
|
||||||
# pylint: disable-next=import-outside-toplevel
|
# pylint: disable-next=import-outside-toplevel
|
||||||
from .core_config import Config
|
from .core_config import Config
|
||||||
|
|
||||||
@ -443,7 +440,6 @@ class HomeAssistant:
|
|||||||
self.states = StateMachine(self.bus, self.loop)
|
self.states = StateMachine(self.bus, self.loop)
|
||||||
self.config = Config(self, config_dir)
|
self.config = Config(self, config_dir)
|
||||||
self.config.async_initialize()
|
self.config.async_initialize()
|
||||||
self.helpers = loader.Helpers(self)
|
|
||||||
self.state: CoreState = CoreState.not_running
|
self.state: CoreState = CoreState.not_running
|
||||||
self.exit_code: int = 0
|
self.exit_code: int = 0
|
||||||
# If not None, use to signal end-of-loop
|
# If not None, use to signal end-of-loop
|
||||||
|
@ -1710,37 +1710,6 @@ class ModuleWrapper:
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class Helpers:
|
|
||||||
"""Helper to load helpers."""
|
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant) -> None:
|
|
||||||
"""Initialize the Helpers class."""
|
|
||||||
self._hass = hass
|
|
||||||
|
|
||||||
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
|
|
||||||
# pylint: disable-next=import-outside-toplevel
|
|
||||||
from .helpers.frame import ReportBehavior, report_usage
|
|
||||||
|
|
||||||
report_usage(
|
|
||||||
(
|
|
||||||
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)
|
|
||||||
setattr(self, helper_name, wrapped)
|
|
||||||
return wrapped
|
|
||||||
|
|
||||||
|
|
||||||
def bind_hass[_CallableT: Callable[..., Any]](func: _CallableT) -> _CallableT:
|
def bind_hass[_CallableT: Callable[..., Any]](func: _CallableT) -> _CallableT:
|
||||||
"""Decorate function to indicate that first argument is hass.
|
"""Decorate function to indicate that first argument is hass.
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ from homeassistant.components.flexit_bacnet.const import PRESET_TO_VENTILATION_M
|
|||||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, Platform
|
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_component, entity_registry as er
|
||||||
|
|
||||||
from . import setup_with_selected_platforms
|
from . import setup_with_selected_platforms
|
||||||
|
|
||||||
@ -156,14 +156,14 @@ async def test_hvac_action(
|
|||||||
|
|
||||||
# Simulate electric heater being ON
|
# Simulate electric heater being ON
|
||||||
mock_flexit_bacnet.electric_heater = True
|
mock_flexit_bacnet.electric_heater = True
|
||||||
await hass.helpers.entity_component.async_update_entity(ENTITY_ID)
|
await entity_component.async_update_entity(hass, ENTITY_ID)
|
||||||
|
|
||||||
state = hass.states.get(ENTITY_ID)
|
state = hass.states.get(ENTITY_ID)
|
||||||
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.HEATING
|
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.HEATING
|
||||||
|
|
||||||
# Simulate electric heater being OFF
|
# Simulate electric heater being OFF
|
||||||
mock_flexit_bacnet.electric_heater = False
|
mock_flexit_bacnet.electric_heater = False
|
||||||
await hass.helpers.entity_component.async_update_entity(ENTITY_ID)
|
await entity_component.async_update_entity(hass, ENTITY_ID)
|
||||||
|
|
||||||
state = hass.states.get(ENTITY_ID)
|
state = hass.states.get(ENTITY_ID)
|
||||||
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.FAN
|
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.FAN
|
||||||
|
@ -14,7 +14,7 @@ import pytest
|
|||||||
from homeassistant import loader
|
from homeassistant import loader
|
||||||
from homeassistant.components import hue
|
from homeassistant.components import hue
|
||||||
from homeassistant.components.hue import light as hue_light
|
from homeassistant.components.hue import light as hue_light
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.json import json_dumps
|
from homeassistant.helpers.json import json_dumps
|
||||||
from homeassistant.util.json import json_loads
|
from homeassistant.util.json import json_loads
|
||||||
|
|
||||||
@ -114,25 +114,6 @@ async def test_nonexistent_component_dependencies(hass: HomeAssistant) -> None:
|
|||||||
assert result == {}
|
assert result == {}
|
||||||
|
|
||||||
|
|
||||||
async def test_helpers_wrapper(hass: HomeAssistant) -> None:
|
|
||||||
"""Test helpers wrapper."""
|
|
||||||
helpers = loader.Helpers(hass)
|
|
||||||
|
|
||||||
result = []
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def discovery_callback(service, discovered):
|
|
||||||
"""Handle discovery callback."""
|
|
||||||
result.append(discovered)
|
|
||||||
|
|
||||||
helpers.discovery.async_listen("service_name", discovery_callback)
|
|
||||||
|
|
||||||
await helpers.discovery.async_discover("service_name", "hello", None, {})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result == ["hello"]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("enable_custom_integrations")
|
@pytest.mark.usefixtures("enable_custom_integrations")
|
||||||
async def test_custom_component_name(hass: HomeAssistant) -> None:
|
async def test_custom_component_name(hass: HomeAssistant) -> None:
|
||||||
"""Test the name attribute of custom components."""
|
"""Test the name attribute of custom components."""
|
||||||
@ -1981,42 +1962,6 @@ async def test_has_services(hass: HomeAssistant) -> None:
|
|||||||
assert integration.has_services is True
|
assert integration.has_services is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("integration_frame_path", "expected"),
|
|
||||||
[
|
|
||||||
pytest.param(
|
|
||||||
"custom_components/test_integration_frame", True, id="custom integration"
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"homeassistant/components/test_integration_frame",
|
|
||||||
False,
|
|
||||||
id="core integration",
|
|
||||||
),
|
|
||||||
pytest.param("homeassistant/test_integration_frame", False, id="core"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
@pytest.mark.usefixtures("mock_integration_frame")
|
|
||||||
async def test_hass_helpers_use_reported(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
expected: bool,
|
|
||||||
) -> None:
|
|
||||||
"""Test whether use of hass.helpers is reported."""
|
|
||||||
with (
|
|
||||||
patch(
|
|
||||||
"homeassistant.helpers.aiohttp_client.async_get_clientsession",
|
|
||||||
return_value=None,
|
|
||||||
),
|
|
||||||
):
|
|
||||||
hass.helpers.aiohttp_client.async_get_clientsession()
|
|
||||||
|
|
||||||
reported = (
|
|
||||||
"Detected that custom integration 'test_integration_frame' "
|
|
||||||
"accesses hass.helpers.aiohttp_client, which should be updated"
|
|
||||||
) in caplog.text
|
|
||||||
assert reported == expected
|
|
||||||
|
|
||||||
|
|
||||||
async def test_manifest_json_fragment_round_trip(hass: HomeAssistant) -> None:
|
async def test_manifest_json_fragment_round_trip(hass: HomeAssistant) -> None:
|
||||||
"""Test json_fragment roundtrip."""
|
"""Test json_fragment roundtrip."""
|
||||||
integration = await loader.async_get_integration(hass, "hue")
|
integration = await loader.async_get_integration(hass, "hue")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user