Add option to ignore flows (#30008)
This commit is contained in:
1 parent
feb39c39a3
commit
9c7caaa142
6 files changed
+132
-3
No files matched your search
@@ -634,3 +634,42 @@ async def test_update_system_options(hass, hass_ws_client):
|
||||
assert response["success"]
|
||||
assert response["result"]["disable_new_entities"]
|
||||
assert entry.system_options.disable_new_entities
|
||||
|
||||
|
||||
async def test_ignore_flow(hass, hass_ws_client):
|
||||
"""Test we can ignore a flow."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
mock_integration(hass, MockModule("test", async_setup_entry=mock_coro_func(True)))
|
||||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
|
||||
class TestFlow(core_ce.ConfigFlow):
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
await self.async_set_unique_id("mock-unique-id")
|
||||
return self.async_show_form(step_id="account", data_schema=vol.Schema({}))
|
||||
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
with patch.dict(HANDLERS, {"test": TestFlow}):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"test", context={"source": "user"}
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
|
||||
await ws_client.send_json(
|
||||
{
|
||||
"id": 5,
|
||||
"type": "config_entries/ignore_flow",
|
||||
"flow_id": result["flow_id"],
|
||||
}
|
||||
)
|
||||
response = await ws_client.receive_json()
|
||||
|
||||
assert response["success"]
|
||||
|
||||
assert len(hass.config_entries.flow.async_progress()) == 0
|
||||
|
||||
entry = hass.config_entries.async_entries("test")[0]
|
||||
assert entry.source == "ignore"
|
||||
assert entry.unique_id == "mock-unique-id"
|
||||
@@ -6,7 +6,7 @@ import aiohue
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.hue import config_flow, const
|
||||
|
||||
from tests.common import MockConfigEntry, mock_coro
|
||||
@@ -95,6 +95,11 @@ async def test_flow_one_bridge_discovered(hass, aioclient_mock):
|
||||
|
||||
async def test_flow_two_bridges_discovered(hass, aioclient_mock):
|
||||
"""Test config flow discovers two bridges."""
|
||||
# Add ignored config entry. Should still show up as option.
|
||||
MockConfigEntry(
|
||||
domain="hue", source=config_entries.SOURCE_IGNORE, unique_id="bla"
|
||||
).add_to_hass(hass)
|
||||
|
||||
aioclient_mock.get(
|
||||
const.API_NUPNP,
|
||||
json=[
|
||||
|
||||
@@ -1146,3 +1146,43 @@ async def test_finish_flow_aborts_progress(hass, manager):
|
||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
|
||||
assert len(hass.config_entries.flow.async_progress()) == 0
|
||||
|
||||
|
||||
async def test_unique_id_ignore(hass, manager):
|
||||
"""Test that we can ignore flows that are in progress and have a unique ID."""
|
||||
async_setup_entry = MagicMock(return_value=mock_coro(False))
|
||||
mock_integration(hass, MockModule("comp", async_setup_entry=async_setup_entry))
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
await self.async_set_unique_id("mock-unique-id")
|
||||
return self.async_show_form(step_id="discovery")
|
||||
|
||||
with patch.dict(config_entries.HANDLERS, {"comp": TestFlow}):
|
||||
# Create one to be in progress
|
||||
result = await manager.flow.async_init(
|
||||
"comp", context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
|
||||
result2 = await manager.flow.async_init(
|
||||
"comp",
|
||||
context={"source": config_entries.SOURCE_IGNORE},
|
||||
data={"unique_id": "mock-unique-id"},
|
||||
)
|
||||
|
||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
|
||||
# assert len(hass.config_entries.flow.async_progress()) == 0
|
||||
|
||||
# We should never set up an ignored entry.
|
||||
assert len(async_setup_entry.mock_calls) == 0
|
||||
|
||||
entry = hass.config_entries.async_entries("comp")[0]
|
||||
|
||||
assert entry.source == "ignore"
|
||||
assert entry.unique_id == "mock-unique-id"
|
||||
Reference in new issue
Block a user