mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Remove cloud assist pipeline setup from cloud client (#92056)
This commit is contained in:
@@ -6,11 +6,6 @@ import aiohttp
|
||||
from aiohttp import web
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.assist_pipeline import (
|
||||
Pipeline,
|
||||
async_get_pipeline,
|
||||
async_get_pipelines,
|
||||
)
|
||||
from homeassistant.components.cloud import DOMAIN
|
||||
from homeassistant.components.cloud.client import CloudClient
|
||||
from homeassistant.components.cloud.const import (
|
||||
@@ -303,18 +298,14 @@ async def test_google_config_should_2fa(
|
||||
assert not gconf.should_2fa(state)
|
||||
|
||||
|
||||
@patch(
|
||||
"homeassistant.components.cloud.client.assist_pipeline.async_get_pipelines",
|
||||
return_value=[],
|
||||
)
|
||||
async def test_set_username(async_get_pipelines, hass: HomeAssistant) -> None:
|
||||
async def test_set_username(hass: HomeAssistant) -> None:
|
||||
"""Test we set username during login."""
|
||||
prefs = MagicMock(
|
||||
alexa_enabled=False,
|
||||
google_enabled=False,
|
||||
async_set_username=AsyncMock(return_value=None),
|
||||
)
|
||||
client = CloudClient(hass, prefs, None, {}, {}, AsyncMock())
|
||||
client = CloudClient(hass, prefs, None, {}, {})
|
||||
client.cloud = MagicMock(is_logged_in=True, username="mock-username")
|
||||
await client.on_cloud_connected()
|
||||
|
||||
@@ -322,12 +313,8 @@ async def test_set_username(async_get_pipelines, hass: HomeAssistant) -> None:
|
||||
assert prefs.async_set_username.mock_calls[0][1][0] == "mock-username"
|
||||
|
||||
|
||||
@patch(
|
||||
"homeassistant.components.cloud.client.assist_pipeline.async_get_pipelines",
|
||||
return_value=[],
|
||||
)
|
||||
async def test_login_recovers_bad_internet(
|
||||
async_get_pipelines, hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test Alexa can recover bad auth."""
|
||||
prefs = Mock(
|
||||
@@ -335,7 +322,7 @@ async def test_login_recovers_bad_internet(
|
||||
google_enabled=False,
|
||||
async_set_username=AsyncMock(return_value=None),
|
||||
)
|
||||
client = CloudClient(hass, prefs, None, {}, {}, AsyncMock())
|
||||
client = CloudClient(hass, prefs, None, {}, {})
|
||||
client.cloud = Mock()
|
||||
client._alexa_config = Mock(
|
||||
async_enable_proactive_mode=Mock(side_effect=aiohttp.ClientError)
|
||||
@@ -367,29 +354,3 @@ async def test_system_msg(hass: HomeAssistant) -> None:
|
||||
|
||||
assert response is None
|
||||
assert cloud.client.relayer_region == "xx-earth-616"
|
||||
|
||||
|
||||
async def test_create_cloud_assist_pipeline(
|
||||
hass: HomeAssistant, mock_cloud_setup, mock_cloud_login
|
||||
) -> None:
|
||||
"""Test creating a cloud enabled assist pipeline."""
|
||||
cloud_client: CloudClient = hass.data[DOMAIN].client
|
||||
await cloud_client.cloud_started()
|
||||
assert cloud_client.cloud_pipeline is None
|
||||
assert len(async_get_pipelines(hass)) == 1
|
||||
|
||||
await cloud_client.create_cloud_assist_pipeline()
|
||||
assert cloud_client.cloud_pipeline is not None
|
||||
assert len(async_get_pipelines(hass)) == 2
|
||||
assert async_get_pipeline(hass, cloud_client.cloud_pipeline) == Pipeline(
|
||||
conversation_engine="homeassistant",
|
||||
conversation_language="en",
|
||||
id=cloud_client.cloud_pipeline,
|
||||
language="en",
|
||||
name="Home Assistant Cloud",
|
||||
stt_engine="cloud",
|
||||
stt_language="en-US",
|
||||
tts_engine="cloud",
|
||||
tts_language="en-US",
|
||||
tts_voice="JennyNeural",
|
||||
)
|
||||
|
||||
@@ -104,45 +104,68 @@ async def test_google_actions_sync_fails(
|
||||
|
||||
|
||||
async def test_login_view(hass: HomeAssistant, cloud_client) -> None:
|
||||
"""Test logging in."""
|
||||
create_cloud_assist_pipeline_mock = AsyncMock()
|
||||
hass.data["cloud"] = MagicMock(
|
||||
login=AsyncMock(),
|
||||
client=Mock(
|
||||
cloud_pipeline="12345",
|
||||
create_cloud_assist_pipeline=create_cloud_assist_pipeline_mock,
|
||||
),
|
||||
)
|
||||
"""Test logging in when an assist pipeline is available."""
|
||||
hass.data["cloud"] = MagicMock(login=AsyncMock())
|
||||
|
||||
req = await cloud_client.post(
|
||||
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.components.cloud.http_api.assist_pipeline.async_get_pipelines",
|
||||
return_value=[
|
||||
Mock(
|
||||
conversation_engine="homeassistant",
|
||||
id="12345",
|
||||
stt_engine=DOMAIN,
|
||||
tts_engine=DOMAIN,
|
||||
)
|
||||
],
|
||||
), patch(
|
||||
"homeassistant.components.cloud.http_api.assist_pipeline.async_create_default_pipeline",
|
||||
) as create_pipeline_mock:
|
||||
req = await cloud_client.post(
|
||||
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
|
||||
)
|
||||
|
||||
assert req.status == HTTPStatus.OK
|
||||
result = await req.json()
|
||||
assert result == {"success": True, "cloud_pipeline": "12345"}
|
||||
create_cloud_assist_pipeline_mock.assert_not_awaited()
|
||||
create_pipeline_mock.assert_not_awaited()
|
||||
|
||||
|
||||
async def test_login_view_create_pipeline(hass: HomeAssistant, cloud_client) -> None:
|
||||
"""Test logging in when no assist pipeline is available."""
|
||||
create_cloud_assist_pipeline_mock = AsyncMock()
|
||||
hass.data["cloud"] = MagicMock(
|
||||
login=AsyncMock(),
|
||||
client=Mock(
|
||||
cloud_pipeline=None,
|
||||
create_cloud_assist_pipeline=create_cloud_assist_pipeline_mock,
|
||||
),
|
||||
)
|
||||
hass.data["cloud"] = MagicMock(login=AsyncMock())
|
||||
|
||||
req = await cloud_client.post(
|
||||
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.components.cloud.http_api.assist_pipeline.async_create_default_pipeline",
|
||||
return_value=AsyncMock(id="12345"),
|
||||
) as create_pipeline_mock:
|
||||
req = await cloud_client.post(
|
||||
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
|
||||
)
|
||||
|
||||
assert req.status == HTTPStatus.OK
|
||||
result = await req.json()
|
||||
assert result == {"success": True, "cloud_pipeline": "12345"}
|
||||
create_pipeline_mock.assert_awaited_once_with(hass, "cloud", "cloud")
|
||||
|
||||
|
||||
async def test_login_view_create_pipeline_fail(
|
||||
hass: HomeAssistant, cloud_client
|
||||
) -> None:
|
||||
"""Test logging in when no assist pipeline is available."""
|
||||
hass.data["cloud"] = MagicMock(login=AsyncMock())
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.cloud.http_api.assist_pipeline.async_create_default_pipeline",
|
||||
return_value=None,
|
||||
) as create_pipeline_mock:
|
||||
req = await cloud_client.post(
|
||||
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
|
||||
)
|
||||
|
||||
assert req.status == HTTPStatus.OK
|
||||
result = await req.json()
|
||||
assert result == {"success": True, "cloud_pipeline": None}
|
||||
create_cloud_assist_pipeline_mock.assert_awaited_once()
|
||||
create_pipeline_mock.assert_awaited_once_with(hass, "cloud", "cloud")
|
||||
|
||||
|
||||
async def test_login_view_random_exception(cloud_client) -> None:
|
||||
|
||||
@@ -155,17 +155,24 @@ async def test_on_connect(hass: HomeAssistant, mock_cloud_fixture) -> None:
|
||||
|
||||
assert len(hass.states.async_entity_ids("binary_sensor")) == 0
|
||||
|
||||
await cl.client.cloud_started()
|
||||
# The on_start callback discovers the binary sensor platform
|
||||
assert "async_setup" in str(cl._on_start[-1])
|
||||
await cl._on_start[-1]()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_entity_ids("binary_sensor")) == 1
|
||||
|
||||
with patch("homeassistant.helpers.discovery.async_load_platform") as mock_load:
|
||||
await cl.iot._on_connect[-1]()
|
||||
await cl._on_start[-1]()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_load.mock_calls) == 0
|
||||
|
||||
assert len(cloud_states) == 1
|
||||
assert cloud_states[-1] == cloud.CloudConnectionState.CLOUD_CONNECTED
|
||||
|
||||
await cl.iot._on_connect[-1]()
|
||||
await hass.async_block_till_done()
|
||||
assert len(cloud_states) == 2
|
||||
assert cloud_states[-1] == cloud.CloudConnectionState.CLOUD_CONNECTED
|
||||
|
||||
@@ -177,6 +184,11 @@ async def test_on_connect(hass: HomeAssistant, mock_cloud_fixture) -> None:
|
||||
assert len(cloud_states) == 3
|
||||
assert cloud_states[-1] == cloud.CloudConnectionState.CLOUD_DISCONNECTED
|
||||
|
||||
await cl.iot._on_disconnect[-1]()
|
||||
await hass.async_block_till_done()
|
||||
assert len(cloud_states) == 4
|
||||
assert cloud_states[-1] == cloud.CloudConnectionState.CLOUD_DISCONNECTED
|
||||
|
||||
|
||||
async def test_remote_ui_url(hass: HomeAssistant, mock_cloud_fixture) -> None:
|
||||
"""Test getting remote ui url."""
|
||||
|
||||
@@ -48,8 +48,9 @@ async def test_prefs_default_voice(
|
||||
"""Test cloud provider uses the preferences."""
|
||||
assert cloud_prefs.tts_default_voice == ("en-US", "female")
|
||||
|
||||
tts_info = {"platform_loaded": Mock()}
|
||||
provider_pref = await tts.async_get_engine(
|
||||
Mock(data={const.DOMAIN: cloud_with_prefs}), None, {}
|
||||
Mock(data={const.DOMAIN: cloud_with_prefs}), None, tts_info
|
||||
)
|
||||
provider_conf = await tts.async_get_engine(
|
||||
Mock(data={const.DOMAIN: cloud_with_prefs}),
|
||||
@@ -73,8 +74,9 @@ async def test_prefs_default_voice(
|
||||
|
||||
async def test_provider_properties(cloud_with_prefs) -> None:
|
||||
"""Test cloud provider."""
|
||||
tts_info = {"platform_loaded": Mock()}
|
||||
provider = await tts.async_get_engine(
|
||||
Mock(data={const.DOMAIN: cloud_with_prefs}), None, {}
|
||||
Mock(data={const.DOMAIN: cloud_with_prefs}), None, tts_info
|
||||
)
|
||||
assert provider.supported_options == ["gender", "voice", "audio_output"]
|
||||
assert "nl-NL" in provider.supported_languages
|
||||
@@ -85,8 +87,9 @@ async def test_provider_properties(cloud_with_prefs) -> None:
|
||||
|
||||
async def test_get_tts_audio(cloud_with_prefs) -> None:
|
||||
"""Test cloud provider."""
|
||||
tts_info = {"platform_loaded": Mock()}
|
||||
provider = await tts.async_get_engine(
|
||||
Mock(data={const.DOMAIN: cloud_with_prefs}), None, {}
|
||||
Mock(data={const.DOMAIN: cloud_with_prefs}), None, tts_info
|
||||
)
|
||||
assert provider.supported_options == ["gender", "voice", "audio_output"]
|
||||
assert "nl-NL" in provider.supported_languages
|
||||
|
||||
Reference in New Issue
Block a user