From 66ac5d5b766f904a2650e176484b70e49350383d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 6 Apr 2020 12:24:08 -0500 Subject: [PATCH] =?UTF-8?q?Abort=20rachio=20config=20flow=20if=20the=20api?= =?UTF-8?q?=20key=20is=20already=20configured=E2=80=A6=20(#33747)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now abort before hitting the api which can be slow and block startup if importing from yaml. --- homeassistant/components/rachio/config_flow.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/rachio/config_flow.py b/homeassistant/components/rachio/config_flow.py index 9eff7c99334..64e78a24f4a 100644 --- a/homeassistant/components/rachio/config_flow.py +++ b/homeassistant/components/rachio/config_flow.py @@ -62,9 +62,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Handle the initial step.""" errors = {} if user_input is not None: + await self.async_set_unique_id(user_input[CONF_API_KEY]) + 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) except CannotConnect: errors["base"] = "cannot_connect" except InvalidAuth: @@ -73,11 +75,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): _LOGGER.exception("Unexpected exception") errors["base"] = "unknown" - if "base" not in errors: - await self.async_set_unique_id(user_input[CONF_API_KEY]) - self._abort_if_unique_id_configured() - return self.async_create_entry(title=info["title"], data=user_input) - return self.async_show_form( step_id="user", data_schema=DATA_SCHEMA, errors=errors )