diff --git a/homeassistant/components/solaredge/config_flow.py b/homeassistant/components/solaredge/config_flow.py index 8a7f2af3a99..49c265b4221 100644 --- a/homeassistant/components/solaredge/config_flow.py +++ b/homeassistant/components/solaredge/config_flow.py @@ -41,15 +41,14 @@ class SolarEdgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): api = solaredge.Solaredge(api_key) try: response = api.get_details(site_id) - except (ConnectTimeout, HTTPError): - self._errors[CONF_SITE_ID] = "could_not_connect" - return False - try: if response["details"]["status"].lower() != "active": self._errors[CONF_SITE_ID] = "site_not_active" return False + except (ConnectTimeout, HTTPError): + self._errors[CONF_SITE_ID] = "could_not_connect" + return False except KeyError: - self._errors[CONF_SITE_ID] = "api_failure" + self._errors[CONF_SITE_ID] = "invalid_api_key" return False return True @@ -59,7 +58,7 @@ class SolarEdgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): if user_input is not None: name = slugify(user_input.get(CONF_NAME, DEFAULT_NAME)) if self._site_in_configuration_exists(user_input[CONF_SITE_ID]): - self._errors[CONF_SITE_ID] = "site_exists" + self._errors[CONF_SITE_ID] = "already_configured" else: site = user_input[CONF_SITE_ID] api = user_input[CONF_API_KEY] @@ -94,5 +93,5 @@ class SolarEdgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_import(self, user_input=None): """Import a config entry.""" if self._site_in_configuration_exists(user_input[CONF_SITE_ID]): - return self.async_abort(reason="site_exists") + return self.async_abort(reason="already_configured") return await self.async_step_user(user_input) diff --git a/homeassistant/components/solaredge/strings.json b/homeassistant/components/solaredge/strings.json index eb4c5cda1fd..b6f258b0dc8 100644 --- a/homeassistant/components/solaredge/strings.json +++ b/homeassistant/components/solaredge/strings.json @@ -11,10 +11,13 @@ } }, "error": { - "site_exists": "This site_id is already configured" + "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", + "invalid_api_key": "[%key:common::config_flow::error::invalid_api_key%]", + "site_not_active": "The site is not active", + "could_not_connect": "Could not connect to the solaredge API" }, "abort": { - "site_exists": "This site_id is already configured" + "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" } } -} \ No newline at end of file +} diff --git a/tests/components/solaredge/test_config_flow.py b/tests/components/solaredge/test_config_flow.py index 61bc5f9ac6c..835fc300982 100644 --- a/tests/components/solaredge/test_config_flow.py +++ b/tests/components/solaredge/test_config_flow.py @@ -85,14 +85,14 @@ async def test_abort_if_already_setup(hass, test_api): {CONF_NAME: DEFAULT_NAME, CONF_SITE_ID: SITE_ID, CONF_API_KEY: API_KEY} ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "site_exists" + assert result["reason"] == "already_configured" # user: Should fail, same SITE_ID result = await flow.async_step_user( {CONF_NAME: "test", CONF_SITE_ID: SITE_ID, CONF_API_KEY: "test"} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM - assert result["errors"] == {CONF_SITE_ID: "site_exists"} + assert result["errors"] == {CONF_SITE_ID: "already_configured"} async def test_asserts(hass, test_api): @@ -113,7 +113,7 @@ async def test_asserts(hass, test_api): {CONF_NAME: NAME, CONF_API_KEY: API_KEY, CONF_SITE_ID: SITE_ID} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM - assert result["errors"] == {CONF_SITE_ID: "api_failure"} + assert result["errors"] == {CONF_SITE_ID: "invalid_api_key"} # test with ConnectionTimeout test_api.get_details.side_effect = ConnectTimeout()