mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 04:05:20 +01:00
Cleanup deprecated hassio constants and functions (#158802)
This commit is contained in:
@@ -5,7 +5,6 @@ from __future__ import annotations
|
|||||||
import asyncio
|
import asyncio
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import partial
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@@ -42,24 +41,9 @@ from homeassistant.helpers import (
|
|||||||
issue_registry as ir,
|
issue_registry as ir,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.deprecation import (
|
|
||||||
DeprecatedConstant,
|
|
||||||
all_with_deprecated_constants,
|
|
||||||
check_if_deprecated_constant,
|
|
||||||
deprecated_function,
|
|
||||||
dir_with_deprecated_constants,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
from homeassistant.helpers.hassio import (
|
|
||||||
get_supervisor_ip as _get_supervisor_ip,
|
|
||||||
is_hassio as _is_hassio,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity
|
from homeassistant.helpers.issue_registry import IssueSeverity
|
||||||
from homeassistant.helpers.service_info.hassio import (
|
|
||||||
HassioServiceInfo as _HassioServiceInfo,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.loader import bind_hass
|
|
||||||
from homeassistant.util.async_ import create_eager_task
|
from homeassistant.util.async_ import create_eager_task
|
||||||
from homeassistant.util.dt import now
|
from homeassistant.util.dt import now
|
||||||
|
|
||||||
@@ -134,14 +118,6 @@ from .websocket_api import async_load_websocket_api
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
get_supervisor_ip = deprecated_function(
|
|
||||||
"homeassistant.helpers.hassio.get_supervisor_ip", breaks_in_ha_version="2025.11"
|
|
||||||
)(_get_supervisor_ip)
|
|
||||||
_DEPRECATED_HassioServiceInfo = DeprecatedConstant(
|
|
||||||
_HassioServiceInfo,
|
|
||||||
"homeassistant.helpers.service_info.hassio.HassioServiceInfo",
|
|
||||||
"2025.11",
|
|
||||||
)
|
|
||||||
|
|
||||||
# If new platforms are added, be sure to import them above
|
# If new platforms are added, be sure to import them above
|
||||||
# so we do not make other components that depend on hassio
|
# so we do not make other components that depend on hassio
|
||||||
@@ -302,19 +278,6 @@ def hostname_from_addon_slug(addon_slug: str) -> str:
|
|||||||
return addon_slug.replace("_", "-")
|
return addon_slug.replace("_", "-")
|
||||||
|
|
||||||
|
|
||||||
@callback
|
|
||||||
@deprecated_function(
|
|
||||||
"homeassistant.helpers.hassio.is_hassio", breaks_in_ha_version="2025.11"
|
|
||||||
)
|
|
||||||
@bind_hass
|
|
||||||
def is_hassio(hass: HomeAssistant) -> bool:
|
|
||||||
"""Return true if Hass.io is loaded.
|
|
||||||
|
|
||||||
Async friendly.
|
|
||||||
"""
|
|
||||||
return _is_hassio(hass)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: C901
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: C901
|
||||||
"""Set up the Hass.io component."""
|
"""Set up the Hass.io component."""
|
||||||
# Check local setup
|
# Check local setup
|
||||||
@@ -628,11 +591,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.data.pop(ADDONS_COORDINATOR, None)
|
hass.data.pop(ADDONS_COORDINATOR, None)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
# These can be removed if no deprecated constant are in this module anymore
|
|
||||||
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
|
|
||||||
__dir__ = partial(
|
|
||||||
dir_with_deprecated_constants, module_globals_keys=[*globals().keys()]
|
|
||||||
)
|
|
||||||
__all__ = all_with_deprecated_constants(globals())
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ def disable_bluetooth_auto_recovery():
|
|||||||
def mock_operating_system_85():
|
def mock_operating_system_85():
|
||||||
"""Mock running Home Assistant Operating system 8.5."""
|
"""Mock running Home Assistant Operating system 8.5."""
|
||||||
with (
|
with (
|
||||||
patch("homeassistant.components.hassio.is_hassio", return_value=True),
|
patch("homeassistant.helpers.hassio.is_hassio", return_value=True),
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.hassio.get_os_info",
|
"homeassistant.components.hassio.get_os_info",
|
||||||
return_value={
|
return_value={
|
||||||
@@ -67,7 +67,7 @@ def mock_operating_system_85():
|
|||||||
def mock_operating_system_90():
|
def mock_operating_system_90():
|
||||||
"""Mock running Home Assistant Operating system 9.0."""
|
"""Mock running Home Assistant Operating system 9.0."""
|
||||||
with (
|
with (
|
||||||
patch("homeassistant.components.hassio.is_hassio", return_value=True),
|
patch("homeassistant.helpers.hassio.is_hassio", return_value=True),
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.hassio.get_os_info",
|
"homeassistant.components.hassio.get_os_info",
|
||||||
return_value={
|
return_value={
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
"""The tests for the hassio component."""
|
"""The tests for the hassio component."""
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
@@ -13,15 +12,13 @@ import pytest
|
|||||||
from voluptuous import Invalid
|
from voluptuous import Invalid
|
||||||
|
|
||||||
from homeassistant.auth.const import GROUP_ID_ADMIN
|
from homeassistant.auth.const import GROUP_ID_ADMIN
|
||||||
from homeassistant.components import frontend, hassio
|
from homeassistant.components import frontend
|
||||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||||
from homeassistant.components.hassio import (
|
from homeassistant.components.hassio import (
|
||||||
ADDONS_COORDINATOR,
|
ADDONS_COORDINATOR,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
get_core_info,
|
get_core_info,
|
||||||
get_supervisor_ip,
|
|
||||||
hostname_from_addon_slug,
|
hostname_from_addon_slug,
|
||||||
is_hassio as deprecated_is_hassio,
|
|
||||||
)
|
)
|
||||||
from homeassistant.components.hassio.config import STORAGE_KEY
|
from homeassistant.components.hassio.config import STORAGE_KEY
|
||||||
from homeassistant.components.hassio.const import (
|
from homeassistant.components.hassio.const import (
|
||||||
@@ -32,15 +29,10 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, issue_registry as ir
|
from homeassistant.helpers import device_registry as dr, issue_registry as ir
|
||||||
from homeassistant.helpers.hassio import is_hassio
|
from homeassistant.helpers.hassio import is_hassio
|
||||||
from homeassistant.helpers.service_info.hassio import HassioServiceInfo
|
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
MockConfigEntry,
|
|
||||||
async_fire_time_changed,
|
|
||||||
import_and_test_deprecated_constant,
|
|
||||||
)
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
||||||
@@ -1089,69 +1081,6 @@ def test_hostname_from_addon_slug() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_function_is_hassio(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
|
||||||
"""Test calling deprecated_is_hassio function will create log entry."""
|
|
||||||
|
|
||||||
deprecated_is_hassio(hass)
|
|
||||||
assert caplog.record_tuples == [
|
|
||||||
(
|
|
||||||
"homeassistant.components.hassio",
|
|
||||||
logging.WARNING,
|
|
||||||
"The deprecated function is_hassio was called. It will be "
|
|
||||||
"removed in HA Core 2025.11. Use homeassistant.helpers"
|
|
||||||
".hassio.is_hassio instead",
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_function_get_supervisor_ip(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
|
||||||
"""Test calling get_supervisor_ip function will create log entry."""
|
|
||||||
|
|
||||||
get_supervisor_ip()
|
|
||||||
assert caplog.record_tuples == [
|
|
||||||
(
|
|
||||||
"homeassistant.helpers.hassio",
|
|
||||||
logging.WARNING,
|
|
||||||
"The deprecated function get_supervisor_ip was called. It will "
|
|
||||||
"be removed in HA Core 2025.11. Use homeassistant.helpers"
|
|
||||||
".hassio.get_supervisor_ip instead",
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("constant_name", "replacement_name", "replacement"),
|
|
||||||
[
|
|
||||||
(
|
|
||||||
"HassioServiceInfo",
|
|
||||||
"homeassistant.helpers.service_info.hassio.HassioServiceInfo",
|
|
||||||
HassioServiceInfo,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_deprecated_constants(
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
constant_name: str,
|
|
||||||
replacement_name: str,
|
|
||||||
replacement: Any,
|
|
||||||
) -> None:
|
|
||||||
"""Test deprecated automation constants."""
|
|
||||||
import_and_test_deprecated_constant(
|
|
||||||
caplog,
|
|
||||||
hassio,
|
|
||||||
constant_name,
|
|
||||||
replacement_name,
|
|
||||||
replacement,
|
|
||||||
"2025.11",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("board", "issue_id"),
|
("board", "issue_id"),
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -663,7 +663,7 @@ async def test_get_request_host_no_host_header(hass: HomeAssistant) -> None:
|
|||||||
assert _get_request_host() is None
|
assert _get_request_host() is None
|
||||||
|
|
||||||
|
|
||||||
@patch("homeassistant.components.hassio.is_hassio", Mock(return_value=True))
|
@patch("homeassistant.helpers.hassio.is_hassio", Mock(return_value=True))
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.components.hassio.get_host_info",
|
"homeassistant.components.hassio.get_host_info",
|
||||||
Mock(return_value={"hostname": "homeassistant"}),
|
Mock(return_value={"hostname": "homeassistant"}),
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ async def test_get_system_info_supervisor_not_available(
|
|||||||
patch("platform.system", return_value="Linux"),
|
patch("platform.system", return_value="Linux"),
|
||||||
patch("homeassistant.helpers.system_info.is_docker_env", return_value=True),
|
patch("homeassistant.helpers.system_info.is_docker_env", return_value=True),
|
||||||
patch("homeassistant.helpers.system_info.is_official_image", return_value=True),
|
patch("homeassistant.helpers.system_info.is_official_image", return_value=True),
|
||||||
patch.object(hassio, "is_hassio", return_value=True),
|
patch("homeassistant.helpers.hassio.is_hassio", return_value=True),
|
||||||
patch.object(hassio, "get_info", return_value=None),
|
patch.object(hassio, "get_info", return_value=None),
|
||||||
patch("homeassistant.helpers.system_info.cached_get_user", return_value="root"),
|
patch("homeassistant.helpers.system_info.cached_get_user", return_value="root"),
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user