From ee1644c24e0936257db2f8c6c5d017ac7c54b36b Mon Sep 17 00:00:00 2001
From: Anthony Mattas <anthony@mattas.net>
Date: Mon, 10 Apr 2023 12:37:36 -0400
Subject: [PATCH] Fix configuring Flo instances  (#90990)

* Update config_flow.py

Used constant string for consistency

* Update config_flow.py

Removed code for location ID and name the integration using the username

* Update manifest.json

Updated codeowners

* Update config_flow.py

* Update config_flow.py

Formatted with black

* Update manifest.json

Updated codeowners

* Update test_config_flow.py

Updated test
---
 homeassistant/components/flo/config_flow.py | 19 ++++++++-----------
 tests/components/flo/test_config_flow.py    |  2 +-
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/homeassistant/components/flo/config_flow.py b/homeassistant/components/flo/config_flow.py
index 306ec945a3e..c34753c3295 100644
--- a/homeassistant/components/flo/config_flow.py
+++ b/homeassistant/components/flo/config_flow.py
@@ -9,7 +9,9 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
 
 from .const import DOMAIN, LOGGER
 
-DATA_SCHEMA = vol.Schema({vol.Required("username"): str, vol.Required("password"): str})
+DATA_SCHEMA = vol.Schema(
+    {vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
+)
 
 
 async def validate_input(hass: core.HomeAssistant, data):
@@ -20,18 +22,11 @@ async def validate_input(hass: core.HomeAssistant, data):
 
     session = async_get_clientsession(hass)
     try:
-        api = await async_get_api(
-            data[CONF_USERNAME], data[CONF_PASSWORD], session=session
-        )
+        await async_get_api(data[CONF_USERNAME], data[CONF_PASSWORD], session=session)
     except RequestError as request_error:
         LOGGER.error("Error connecting to the Flo API: %s", request_error)
         raise CannotConnect from request_error
 
-    user_info = await api.user.get_info()
-    a_location_id = user_info["locations"][0]["id"]
-    location_info = await api.location.get_info(a_location_id)
-    return {"title": location_info["nickname"]}
-
 
 class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
     """Handle a config flow for flo."""
@@ -45,8 +40,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
             await self.async_set_unique_id(user_input[CONF_USERNAME])
             self._abort_if_unique_id_configured()
             try:
-                info = await validate_input(self.hass, user_input)
-                return self.async_create_entry(title=info["title"], data=user_input)
+                await validate_input(self.hass, user_input)
+                return self.async_create_entry(
+                    title=user_input[CONF_USERNAME], data=user_input
+                )
             except CannotConnect:
                 errors["base"] = "cannot_connect"
 
diff --git a/tests/components/flo/test_config_flow.py b/tests/components/flo/test_config_flow.py
index 747418c807a..703689e7c36 100644
--- a/tests/components/flo/test_config_flow.py
+++ b/tests/components/flo/test_config_flow.py
@@ -31,7 +31,7 @@ async def test_form(hass: HomeAssistant, aioclient_mock_fixture) -> None:
         )
 
         assert result2["type"] == "create_entry"
-        assert result2["title"] == "Home"
+        assert result2["title"] == TEST_USER_ID
         assert result2["data"] == {"username": TEST_USER_ID, "password": TEST_PASSWORD}
         await hass.async_block_till_done()
         assert len(mock_setup_entry.mock_calls) == 1
-- 
GitLab