From cb8c9bd701d90c5fd3aedff7a6a393a45e47de7b Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 11 Jan 2021 15:54:56 +0000 Subject: [PATCH 1/2] Add name to ignored entries --- homeassistant/components/config/config_entries.py | 6 ++++-- homeassistant/config_entries.py | 2 +- tests/components/config/test_config_entries.py | 2 ++ tests/test_config_entries.py | 12 ++++++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/config/config_entries.py b/homeassistant/components/config/config_entries.py index f67bfb98641163..b8d9944d7af34e 100644 --- a/homeassistant/components/config/config_entries.py +++ b/homeassistant/components/config/config_entries.py @@ -318,7 +318,9 @@ async def config_entry_update(hass, connection, msg): @websocket_api.require_admin @websocket_api.async_response -@websocket_api.websocket_command({"type": "config_entries/ignore_flow", "flow_id": str}) +@websocket_api.websocket_command( + {"type": "config_entries/ignore_flow", "flow_id": str, "title": str} +) async def ignore_config_flow(hass, connection, msg): """Ignore a config flow.""" flow = next( @@ -345,7 +347,7 @@ async def ignore_config_flow(hass, connection, msg): await hass.config_entries.flow.async_init( flow["handler"], context={"source": config_entries.SOURCE_IGNORE}, - data={"unique_id": flow["context"]["unique_id"]}, + data={"unique_id": flow["context"]["unique_id"], "title": msg["title"]}, ) connection.send_result(msg["id"]) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 601ce1efbfeb9d..f87e76edec8315 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -975,7 +975,7 @@ def _async_in_progress(self) -> List[Dict]: async def async_step_ignore(self, user_input: Dict[str, Any]) -> Dict[str, Any]: """Ignore this config flow.""" await self.async_set_unique_id(user_input["unique_id"], raise_on_progress=False) - return self.async_create_entry(title="Ignored", data={}) + return self.async_create_entry(title=user_input["title"], data={}) async def async_step_unignore(self, user_input: Dict[str, Any]) -> Dict[str, Any]: """Rediscover a config entry by it's unique_id.""" diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index 6873bc8311a3b9..87b1559a21b126 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -750,6 +750,7 @@ async def async_step_user(self, user_input=None): "id": 5, "type": "config_entries/ignore_flow", "flow_id": result["flow_id"], + "title": "Test Integration", } ) response = await ws_client.receive_json() @@ -761,3 +762,4 @@ async def async_step_user(self, user_input=None): entry = hass.config_entries.async_entries("test")[0] assert entry.source == "ignore" assert entry.unique_id == "mock-unique-id" + assert entry.title == "Test Integration" diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index a048f5a70431ee..56387069fe4dbe 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -1523,7 +1523,7 @@ async def async_step_user(self, user_input=None): result2 = await manager.flow.async_init( "comp", context={"source": config_entries.SOURCE_IGNORE}, - data={"unique_id": "mock-unique-id"}, + data={"unique_id": "mock-unique-id", "title": "Ignored Title"}, ) assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY @@ -1537,6 +1537,7 @@ async def async_step_user(self, user_input=None): assert entry.source == "ignore" assert entry.unique_id == "mock-unique-id" + assert entry.title == "Ignored Title" async def test_manual_add_overrides_ignored_entry(hass, manager): @@ -1605,7 +1606,7 @@ async def async_step_unignore(self, user_input): result = await manager.flow.async_init( "comp", context={"source": config_entries.SOURCE_IGNORE}, - data={"unique_id": "mock-unique-id"}, + data={"unique_id": "mock-unique-id", "title": "Ignored Title"}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY @@ -1613,6 +1614,7 @@ async def async_step_unignore(self, user_input): assert entry.source == "ignore" assert entry.unique_id == "mock-unique-id" assert entry.domain == "comp" + assert entry.title == "Ignored Title" await manager.async_remove(entry.entry_id) @@ -1649,7 +1651,7 @@ async def async_step_unignore(self, user_input): result = await manager.flow.async_init( "comp", context={"source": config_entries.SOURCE_IGNORE}, - data={"unique_id": "mock-unique-id"}, + data={"unique_id": "mock-unique-id", "title": "Ignored Title"}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY @@ -1657,6 +1659,7 @@ async def async_step_unignore(self, user_input): assert entry.source == "ignore" assert entry.unique_id == "mock-unique-id" assert entry.domain == "comp" + assert entry.title == "Ignored Title" await manager.async_remove(entry.entry_id) @@ -1690,7 +1693,7 @@ class TestFlow(config_entries.ConfigFlow): result = await manager.flow.async_init( "comp", context={"source": config_entries.SOURCE_IGNORE}, - data={"unique_id": "mock-unique-id"}, + data={"unique_id": "mock-unique-id", "title": "Ignored Title"}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY @@ -1698,6 +1701,7 @@ class TestFlow(config_entries.ConfigFlow): assert entry.source == "ignore" assert entry.unique_id == "mock-unique-id" assert entry.domain == "comp" + assert entry.title == "Ignored Title" await manager.async_remove(entry.entry_id) await hass.async_block_till_done() From 5ca797c3ba66eda5b46cb5b07845fb38c662ef7f Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 11 Jan 2021 21:26:29 +0000 Subject: [PATCH 2/2] Fix test --- tests/helpers/test_config_entry_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/helpers/test_config_entry_flow.py b/tests/helpers/test_config_entry_flow.py index a70f6ad8d5c1ca..b5ba206f9081fb 100644 --- a/tests/helpers/test_config_entry_flow.py +++ b/tests/helpers/test_config_entry_flow.py @@ -220,7 +220,7 @@ async def test_ignored_discoveries(hass, discovery_flow_conf): await hass.config_entries.flow.async_init( flow["handler"], context={"source": config_entries.SOURCE_IGNORE}, - data={"unique_id": flow["context"]["unique_id"]}, + data={"unique_id": flow["context"]["unique_id"], "title": "Ignored Entry"}, ) # Second discovery should be aborted