Add ability to ignore heos discovery (#34653)
* Add ability to ignore heos discovery * Fetch player_id, update tests * Handle failure state * Update tests as there are two players in the mock now * Adjust and add more tests * Strip out player id lookup * reverts per review * one more revert
This commit is contained in:
1 parent
cf585babbe
commit
d1be3c8268
4 files changed
+54
-4
No files matched your search
@@ -6,7 +6,8 @@ from pyheos import HeosError
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components import heos, ssdp
|
||||
from homeassistant.components.heos.config_flow import HeosFlowHandler
|
||||
from homeassistant.components.heos.const import DATA_DISCOVERED_HOSTS
|
||||
from homeassistant.components.heos.const import DATA_DISCOVERED_HOSTS, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_SSDP
|
||||
from homeassistant.const import CONF_HOST
|
||||
|
||||
from tests.async_mock import patch
|
||||
@@ -55,6 +56,7 @@ async def test_create_entry_when_host_valid(hass, controller):
|
||||
heos.DOMAIN, context={"source": "user"}, data=data
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["result"].unique_id == DOMAIN
|
||||
assert result["title"] == "Controller (127.0.0.1)"
|
||||
assert result["data"] == data
|
||||
assert controller.connect.call_count == 1
|
||||
@@ -70,6 +72,7 @@ async def test_create_entry_when_friendly_name_valid(hass, controller):
|
||||
heos.DOMAIN, context={"source": "user"}, data=data
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["result"].unique_id == DOMAIN
|
||||
assert result["title"] == "Controller (127.0.0.1)"
|
||||
assert result["data"] == {CONF_HOST: "127.0.0.1"}
|
||||
assert controller.connect.call_count == 1
|
||||
@@ -79,28 +82,34 @@ async def test_create_entry_when_friendly_name_valid(hass, controller):
|
||||
|
||||
async def test_discovery_shows_create_form(hass, controller, discovery_data):
|
||||
"""Test discovery shows form to confirm setup and subsequent abort."""
|
||||
|
||||
await hass.config_entries.flow.async_init(
|
||||
heos.DOMAIN, context={"source": "ssdp"}, data=discovery_data
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
||||
flows_in_progress = hass.config_entries.flow.async_progress()
|
||||
assert flows_in_progress[0]["context"]["unique_id"] == DOMAIN
|
||||
assert len(flows_in_progress) == 1
|
||||
assert hass.data[DATA_DISCOVERED_HOSTS] == {"Office (127.0.0.1)": "127.0.0.1"}
|
||||
|
||||
port = urlparse(discovery_data[ssdp.ATTR_SSDP_LOCATION]).port
|
||||
discovery_data[ssdp.ATTR_SSDP_LOCATION] = f"http://127.0.0.2:{port}/"
|
||||
discovery_data[ssdp.ATTR_UPNP_FRIENDLY_NAME] = "Bedroom"
|
||||
|
||||
await hass.config_entries.flow.async_init(
|
||||
heos.DOMAIN, context={"source": "ssdp"}, data=discovery_data
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
||||
flows_in_progress = hass.config_entries.flow.async_progress()
|
||||
assert flows_in_progress[0]["context"]["unique_id"] == DOMAIN
|
||||
assert len(flows_in_progress) == 1
|
||||
assert hass.data[DATA_DISCOVERED_HOSTS] == {
|
||||
"Office (127.0.0.1)": "127.0.0.1",
|
||||
"Bedroom (127.0.0.2)": "127.0.0.2",
|
||||
}
|
||||
|
||||
|
||||
async def test_disovery_flow_aborts_already_setup(
|
||||
async def test_discovery_flow_aborts_already_setup(
|
||||
hass, controller, discovery_data, config_entry
|
||||
):
|
||||
"""Test discovery flow aborts when entry already setup."""
|
||||
@@ -110,3 +119,34 @@ async def test_disovery_flow_aborts_already_setup(
|
||||
result = await flow.async_step_ssdp(discovery_data)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_setup"
|
||||
|
||||
|
||||
async def test_discovery_sets_the_unique_id(hass, controller, discovery_data):
|
||||
"""Test discovery sets the unique id."""
|
||||
|
||||
port = urlparse(discovery_data[ssdp.ATTR_SSDP_LOCATION]).port
|
||||
discovery_data[ssdp.ATTR_SSDP_LOCATION] = f"http://127.0.0.2:{port}/"
|
||||
discovery_data[ssdp.ATTR_UPNP_FRIENDLY_NAME] = "Bedroom"
|
||||
|
||||
await hass.config_entries.flow.async_init(
|
||||
heos.DOMAIN, context={"source": SOURCE_SSDP}, data=discovery_data
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
flows_in_progress = hass.config_entries.flow.async_progress()
|
||||
assert flows_in_progress[0]["context"]["unique_id"] == DOMAIN
|
||||
assert len(flows_in_progress) == 1
|
||||
assert hass.data[DATA_DISCOVERED_HOSTS] == {"Bedroom (127.0.0.2)": "127.0.0.2"}
|
||||
|
||||
|
||||
async def test_import_sets_the_unique_id(hass, controller):
|
||||
"""Test import sets the unique id."""
|
||||
|
||||
with patch("homeassistant.components.heos.async_setup_entry", return_value=True):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
heos.DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={CONF_HOST: "127.0.0.2"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["result"].unique_id == DOMAIN
|
||||
@@ -31,6 +31,7 @@ async def test_async_setup_creates_entry(hass, config):
|
||||
entry = entries[0]
|
||||
assert entry.title == "Controller (127.0.0.1)"
|
||||
assert entry.data == {CONF_HOST: "127.0.0.1"}
|
||||
assert entry.unique_id == DOMAIN
|
||||
|
||||
|
||||
async def test_async_setup_updates_entry(hass, config_entry, config, controller):
|
||||
@@ -44,6 +45,7 @@ async def test_async_setup_updates_entry(hass, config_entry, config, controller)
|
||||
entry = entries[0]
|
||||
assert entry.title == "Controller (127.0.0.2)"
|
||||
assert entry.data == {CONF_HOST: "127.0.0.2"}
|
||||
assert entry.unique_id == DOMAIN
|
||||
|
||||
|
||||
async def test_async_setup_returns_true(hass, config_entry, config):
|
||||
|
||||
Reference in new issue
Block a user