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 testspull/113691/head
parent
d9bc09e93a
commit
681705394d
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from ipaddress import ip_address
|
from ipaddress import ip_address
|
||||||
from typing import cast
|
|
||||||
|
|
||||||
from hass_nabucasa import remote
|
from hass_nabucasa import remote
|
||||||
import yarl
|
import yarl
|
||||||
|
@ -299,9 +298,16 @@ def _get_external_url(
|
||||||
def _get_cloud_url(hass: HomeAssistant, require_current_request: bool = False) -> str:
|
def _get_cloud_url(hass: HomeAssistant, require_current_request: bool = False) -> str:
|
||||||
"""Get external Home Assistant Cloud URL of this instance."""
|
"""Get external Home Assistant Cloud URL of this instance."""
|
||||||
if "cloud" in hass.config.components:
|
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:
|
try:
|
||||||
cloud_url = yarl.URL(cast(str, hass.components.cloud.async_remote_ui_url()))
|
cloud_url = yarl.URL(async_remote_ui_url(hass))
|
||||||
except hass.components.cloud.CloudNotAvailable as err:
|
except CloudNotAvailable as err:
|
||||||
raise NoURLAvailableError from err
|
raise NoURLAvailableError from err
|
||||||
|
|
||||||
if not require_current_request or cloud_url.host == _get_request_host():
|
if not require_current_request or cloud_url.host == _get_request_host():
|
||||||
|
|
|
@ -5464,9 +5464,8 @@ async def test_camera_discovery(hass: HomeAssistant, mock_stream: None) -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.config.components.add("cloud")
|
hass.config.components.add("cloud")
|
||||||
with patch.object(
|
with patch(
|
||||||
hass.components.cloud,
|
"homeassistant.components.cloud.async_remote_ui_url",
|
||||||
"async_remote_ui_url",
|
|
||||||
return_value="https://example.nabu.casa",
|
return_value="https://example.nabu.casa",
|
||||||
):
|
):
|
||||||
appliance = await discovery_test(device, hass)
|
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")
|
hass.config.components.add("cloud")
|
||||||
with patch.object(
|
with patch(
|
||||||
hass.components.cloud,
|
"homeassistant.components.cloud.async_remote_ui_url",
|
||||||
"async_remote_ui_url",
|
|
||||||
return_value="https://example.nabu.casa",
|
return_value="https://example.nabu.casa",
|
||||||
):
|
):
|
||||||
appliance = await discovery_test(device, hass)
|
appliance = await discovery_test(device, hass)
|
||||||
|
|
|
@ -362,9 +362,8 @@ async def test_get_cloud_url(hass: HomeAssistant) -> None:
|
||||||
assert hass.config.external_url is None
|
assert hass.config.external_url is None
|
||||||
hass.config.components.add("cloud")
|
hass.config.components.add("cloud")
|
||||||
|
|
||||||
with patch.object(
|
with patch(
|
||||||
hass.components.cloud,
|
"homeassistant.components.cloud.async_remote_ui_url",
|
||||||
"async_remote_ui_url",
|
|
||||||
return_value="https://example.nabu.casa",
|
return_value="https://example.nabu.casa",
|
||||||
):
|
):
|
||||||
assert _get_cloud_url(hass) == "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):
|
), pytest.raises(NoURLAvailableError):
|
||||||
_get_cloud_url(hass, require_current_request=True)
|
_get_cloud_url(hass, require_current_request=True)
|
||||||
|
|
||||||
with patch.object(
|
with patch(
|
||||||
hass.components.cloud,
|
"homeassistant.components.cloud.async_remote_ui_url",
|
||||||
"async_remote_ui_url",
|
|
||||||
side_effect=cloud.CloudNotAvailable,
|
side_effect=cloud.CloudNotAvailable,
|
||||||
), pytest.raises(NoURLAvailableError):
|
), pytest.raises(NoURLAvailableError):
|
||||||
_get_cloud_url(hass)
|
_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
|
# Add Cloud to the previous test
|
||||||
hass.config.components.add("cloud")
|
hass.config.components.add("cloud")
|
||||||
with patch.object(
|
with patch(
|
||||||
hass.components.cloud,
|
"homeassistant.components.cloud.async_remote_ui_url",
|
||||||
"async_remote_ui_url",
|
|
||||||
return_value="https://example.nabu.casa",
|
return_value="https://example.nabu.casa",
|
||||||
):
|
):
|
||||||
assert _get_external_url(hass, allow_cloud=False) == "http://1.1.1.1:8123"
|
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
|
# Add Cloud to the previous test
|
||||||
hass.config.components.add("cloud")
|
hass.config.components.add("cloud")
|
||||||
with patch.object(
|
with patch(
|
||||||
hass.components.cloud,
|
"homeassistant.components.cloud.async_remote_ui_url",
|
||||||
"async_remote_ui_url",
|
|
||||||
return_value="https://example.nabu.casa",
|
return_value="https://example.nabu.casa",
|
||||||
):
|
):
|
||||||
assert _get_external_url(hass, allow_cloud=False) == "https://example.com"
|
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:443") is False
|
||||||
assert is_hass_url(hass, "http://example.com") is False
|
assert is_hass_url(hass, "http://example.com") is False
|
||||||
|
|
||||||
with patch.object(
|
with patch(
|
||||||
hass.components.cloud,
|
"homeassistant.components.cloud.async_remote_ui_url",
|
||||||
"async_remote_ui_url",
|
|
||||||
return_value="https://example.nabu.casa",
|
return_value="https://example.nabu.casa",
|
||||||
):
|
):
|
||||||
assert is_hass_url(hass, "https://example.nabu.casa") is False
|
assert is_hass_url(hass, "https://example.nabu.casa") is False
|
||||||
|
|
Loading…
Reference in New Issue