From 7667024a2fdb0479dfd4ff2984dd6f74b6952e57 Mon Sep 17 00:00:00 2001
From: "J. Nick Koston" <nick@koston.org>
Date: Sun, 28 Jan 2024 09:23:07 -1000
Subject: [PATCH] Remove extra confirmation step in tplink authenticated
 discovery flow (#109016)

Remove extra confirmation step in tplink discovery flow

After discovery, and manually entering credentials, we would ask
the user if they still wanted to set up the device. Instead we
now set create the config entry as soon as they enter correct
credentials as its clear that they want to proceed.
---
 .../components/tplink/config_flow.py          |  2 +-
 tests/components/tplink/test_config_flow.py   | 39 ++++---------------
 2 files changed, 8 insertions(+), 33 deletions(-)

diff --git a/homeassistant/components/tplink/config_flow.py b/homeassistant/components/tplink/config_flow.py
index 96d720e59a0..e1e51f19e3a 100644
--- a/homeassistant/components/tplink/config_flow.py
+++ b/homeassistant/components/tplink/config_flow.py
@@ -159,7 +159,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
                 self._discovered_device = device
                 await set_credentials(self.hass, username, password)
                 self.hass.async_create_task(self._async_reload_requires_auth_entries())
-                return await self.async_step_discovery_confirm()
+                return self._async_create_entry_from_device(self._discovered_device)
 
         placeholders = self._async_make_placeholders_from_discovery()
         self.context["title_placeholders"] = placeholders
diff --git a/tests/components/tplink/test_config_flow.py b/tests/components/tplink/test_config_flow.py
index 18e22db60f4..f5b0ba6c41f 100644
--- a/tests/components/tplink/test_config_flow.py
+++ b/tests/components/tplink/test_config_flow.py
@@ -141,18 +141,9 @@ async def test_discovery_auth(
         },
     )
 
-    assert result2["type"] == "form"
-    assert result2["step_id"] == "discovery_confirm"
-    assert not result2["errors"]
-
-    result3 = await hass.config_entries.flow.async_configure(
-        result2["flow_id"], user_input={}
-    )
-
-    await hass.async_block_till_done()
-    assert result3["type"] is FlowResultType.CREATE_ENTRY
-    assert result3["title"] == DEFAULT_ENTRY_TITLE
-    assert result3["data"] == CREATE_ENTRY_DATA_AUTH
+    assert result2["type"] is FlowResultType.CREATE_ENTRY
+    assert result2["title"] == DEFAULT_ENTRY_TITLE
+    assert result2["data"] == CREATE_ENTRY_DATA_AUTH
 
 
 @pytest.mark.parametrize(
@@ -213,17 +204,8 @@ async def test_discovery_auth_errors(
             CONF_PASSWORD: "fake_password",
         },
     )
-    assert result3["type"] is FlowResultType.FORM
-    assert result3["step_id"] == "discovery_confirm"
-
-    await hass.async_block_till_done()
-
-    result4 = await hass.config_entries.flow.async_configure(
-        result3["flow_id"],
-        {},
-    )
-    assert result4["type"] is FlowResultType.CREATE_ENTRY
-    assert result4["data"] == CREATE_ENTRY_DATA_AUTH
+    assert result3["type"] is FlowResultType.CREATE_ENTRY
+    assert result3["data"] == CREATE_ENTRY_DATA_AUTH
 
 
 async def test_discovery_new_credentials(
@@ -325,15 +307,8 @@ async def test_discovery_new_credentials_invalid(
             CONF_PASSWORD: "fake_password",
         },
     )
-    assert result3["type"] is FlowResultType.FORM
-    assert result3["step_id"] == "discovery_confirm"
-
-    result4 = await hass.config_entries.flow.async_configure(
-        result3["flow_id"],
-        {},
-    )
-    assert result4["type"] is FlowResultType.CREATE_ENTRY
-    assert result4["data"] == CREATE_ENTRY_DATA_AUTH
+    assert result3["type"] is FlowResultType.CREATE_ENTRY
+    assert result3["data"] == CREATE_ENTRY_DATA_AUTH
 
 
 async def test_discovery_with_existing_device_present(hass: HomeAssistant) -> None:
-- 
GitLab