Remove deprecated `hass.components` from network helper function (#113615)

* Remove deprecated `hass.components` from network helper function

* Remove deprecated use of `hass.components` in alexa camera tests
pull/113691/head
Jan-Philipp Benecke 2024-03-17 17:42:48 +01:00 committed by GitHub
parent d9bc09e93a
commit 681705394d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 24 deletions

View File

@ -5,7 +5,6 @@ from __future__ import annotations
from collections.abc import Callable
from contextlib import suppress
from ipaddress import ip_address
from typing import cast
from hass_nabucasa import remote
import yarl
@ -299,9 +298,16 @@ def _get_external_url(
def _get_cloud_url(hass: HomeAssistant, require_current_request: bool = False) -> str:
"""Get external Home Assistant Cloud URL of this instance."""
if "cloud" in hass.config.components:
# Local import to avoid circular dependencies
# pylint: disable-next=import-outside-toplevel
from homeassistant.components.cloud import (
CloudNotAvailable,
async_remote_ui_url,
)
try:
cloud_url = yarl.URL(cast(str, hass.components.cloud.async_remote_ui_url()))
except hass.components.cloud.CloudNotAvailable as err:
cloud_url = yarl.URL(async_remote_ui_url(hass))
except CloudNotAvailable as err:
raise NoURLAvailableError from err
if not require_current_request or cloud_url.host == _get_request_host():

View File

@ -5464,9 +5464,8 @@ async def test_camera_discovery(hass: HomeAssistant, mock_stream: None) -> None:
)
hass.config.components.add("cloud")
with patch.object(
hass.components.cloud,
"async_remote_ui_url",
with patch(
"homeassistant.components.cloud.async_remote_ui_url",
return_value="https://example.nabu.casa",
):
appliance = await discovery_test(device, hass)
@ -5495,9 +5494,8 @@ async def test_camera_discovery_without_stream(hass: HomeAssistant) -> None:
)
hass.config.components.add("cloud")
with patch.object(
hass.components.cloud,
"async_remote_ui_url",
with patch(
"homeassistant.components.cloud.async_remote_ui_url",
return_value="https://example.nabu.casa",
):
appliance = await discovery_test(device, hass)

View File

@ -362,9 +362,8 @@ async def test_get_cloud_url(hass: HomeAssistant) -> None:
assert hass.config.external_url is None
hass.config.components.add("cloud")
with patch.object(
hass.components.cloud,
"async_remote_ui_url",
with patch(
"homeassistant.components.cloud.async_remote_ui_url",
return_value="https://example.nabu.casa",
):
assert _get_cloud_url(hass) == "https://example.nabu.casa"
@ -387,9 +386,8 @@ async def test_get_cloud_url(hass: HomeAssistant) -> None:
), pytest.raises(NoURLAvailableError):
_get_cloud_url(hass, require_current_request=True)
with patch.object(
hass.components.cloud,
"async_remote_ui_url",
with patch(
"homeassistant.components.cloud.async_remote_ui_url",
side_effect=cloud.CloudNotAvailable,
), pytest.raises(NoURLAvailableError):
_get_cloud_url(hass)
@ -410,9 +408,8 @@ async def test_get_external_url_cloud_fallback(hass: HomeAssistant) -> None:
# Add Cloud to the previous test
hass.config.components.add("cloud")
with patch.object(
hass.components.cloud,
"async_remote_ui_url",
with patch(
"homeassistant.components.cloud.async_remote_ui_url",
return_value="https://example.nabu.casa",
):
assert _get_external_url(hass, allow_cloud=False) == "http://1.1.1.1:8123"
@ -436,9 +433,8 @@ async def test_get_external_url_cloud_fallback(hass: HomeAssistant) -> None:
# Add Cloud to the previous test
hass.config.components.add("cloud")
with patch.object(
hass.components.cloud,
"async_remote_ui_url",
with patch(
"homeassistant.components.cloud.async_remote_ui_url",
return_value="https://example.nabu.casa",
):
assert _get_external_url(hass, allow_cloud=False) == "https://example.com"
@ -710,9 +706,8 @@ async def test_is_hass_url(hass: HomeAssistant) -> None:
assert is_hass_url(hass, "http://example.com:443") is False
assert is_hass_url(hass, "http://example.com") is False
with patch.object(
hass.components.cloud,
"async_remote_ui_url",
with patch(
"homeassistant.components.cloud.async_remote_ui_url",
return_value="https://example.nabu.casa",
):
assert is_hass_url(hass, "https://example.nabu.casa") is False