mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Avoid setting up harmony websocket from discovery (#57589)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
"""Test the Logitech Harmony Hub config flow."""
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import aiohttp
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.harmony.config_flow import CannotConnect
|
||||
from homeassistant.components.harmony.const import DOMAIN, PREVIOUS_ACTIVE_ACTIVITY
|
||||
@@ -49,11 +51,9 @@ async def test_user_form(hass):
|
||||
async def test_form_ssdp(hass):
|
||||
"""Test we get the form with ssdp source."""
|
||||
|
||||
harmonyapi = _get_mock_harmonyapi(connect=True)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.harmony.util.HarmonyAPI",
|
||||
return_value=harmonyapi,
|
||||
"homeassistant.components.harmony.config_flow.HubConnector.get_remote_id",
|
||||
return_value=1234,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
@@ -75,6 +75,8 @@ async def test_form_ssdp(hass):
|
||||
assert progress[0]["flow_id"] == result["flow_id"]
|
||||
assert progress[0]["context"]["confirm_only"] is True
|
||||
|
||||
harmonyapi = _get_mock_harmonyapi(connect=True)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.harmony.util.HarmonyAPI",
|
||||
return_value=harmonyapi,
|
||||
@@ -94,6 +96,25 @@ async def test_form_ssdp(hass):
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_ssdp_fails_to_get_remote_id(hass):
|
||||
"""Test we abort if we cannot get the remote id."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.harmony.config_flow.HubConnector.get_remote_id",
|
||||
side_effect=aiohttp.ClientError,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data={
|
||||
"friendlyName": "Harmony Hub",
|
||||
"ssdp_location": "http://192.168.1.12:8088/description",
|
||||
},
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
|
||||
async def test_form_ssdp_aborts_before_checking_remoteid_if_host_known(hass):
|
||||
"""Test we abort without connecting if the host is already known."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user