From 9d6589240f185073f6971cef648769e6e9800a41 Mon Sep 17 00:00:00 2001 From: scheric <38077357+scheric@users.noreply.github.com> Date: Sun, 11 Oct 2020 17:11:45 +0200 Subject: [PATCH] Use common strings in logi_circle config flow (#41427) * already_setup->already_configured * auth_error->invalid_auth * rm default * auth_timeout->oauth2_authorize_url_timeout * enable auto format black * add oauth2_missing_configuration * Use standard helper keys Co-authored-by: Martin Hjelmare --- .../components/logi_circle/config_flow.py | 14 ++++++++------ homeassistant/components/logi_circle/strings.json | 11 ++++------- tests/components/logi_circle/test_config_flow.py | 13 ++++++++----- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/logi_circle/config_flow.py b/homeassistant/components/logi_circle/config_flow.py index 55b617c0748..279c3052010 100644 --- a/homeassistant/components/logi_circle/config_flow.py +++ b/homeassistant/components/logi_circle/config_flow.py @@ -67,7 +67,7 @@ class LogiCircleFlowHandler(config_entries.ConfigFlow): async def async_step_import(self, user_input=None): """Handle external yaml configuration.""" if self.hass.config_entries.async_entries(DOMAIN): - return self.async_abort(reason="already_setup") + return self.async_abort(reason="already_configured") self.flow_impl = DOMAIN @@ -78,10 +78,10 @@ class LogiCircleFlowHandler(config_entries.ConfigFlow): flows = self.hass.data.get(DATA_FLOW_IMPL, {}) if self.hass.config_entries.async_entries(DOMAIN): - return self.async_abort(reason="already_setup") + return self.async_abort(reason="already_configured") if not flows: - return self.async_abort(reason="no_flows") + return self.async_abort(reason="missing_configuration") if len(flows) == 1: self.flow_impl = list(flows)[0] @@ -141,7 +141,7 @@ class LogiCircleFlowHandler(config_entries.ConfigFlow): async def async_step_code(self, code=None): """Received code for authentication.""" if self.hass.config_entries.async_entries(DOMAIN): - return self.async_abort(reason="already_setup") + return self.async_abort(reason="already_configured") return await self._async_create_session(code) @@ -167,10 +167,12 @@ class LogiCircleFlowHandler(config_entries.ConfigFlow): with async_timeout.timeout(_TIMEOUT): await logi_session.authorize(code) except AuthorizationFailed: - (self.hass.data[DATA_FLOW_IMPL][DOMAIN][EXTERNAL_ERRORS]) = "auth_error" + (self.hass.data[DATA_FLOW_IMPL][DOMAIN][EXTERNAL_ERRORS]) = "invalid_auth" return self.async_abort(reason="external_error") except asyncio.TimeoutError: - (self.hass.data[DATA_FLOW_IMPL][DOMAIN][EXTERNAL_ERRORS]) = "auth_timeout" + ( + self.hass.data[DATA_FLOW_IMPL][DOMAIN][EXTERNAL_ERRORS] + ) = "authorize_url_timeout" return self.async_abort(reason="external_error") account_id = (await logi_session.account)["accountId"] diff --git a/homeassistant/components/logi_circle/strings.json b/homeassistant/components/logi_circle/strings.json index d96f0e041a1..a73ade9311c 100644 --- a/homeassistant/components/logi_circle/strings.json +++ b/homeassistant/components/logi_circle/strings.json @@ -11,19 +11,16 @@ "description": "Please follow the link below and **Accept** access to your Logi Circle account, then come back and press **Submit** below.\n\n[Link]({authorization_url})" } }, - "create_entry": { - "default": "Successfully authenticated with Logi Circle." - }, "error": { - "auth_error": "API authorization failed.", - "auth_timeout": "Authorization timed out when requesting access token.", + "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", + "authorize_url_timeout": "[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]", "follow_link": "Please follow the link and authenticate before pressing Submit." }, "abort": { - "already_setup": "You can only configure a single Logi Circle account.", + "already_configured": "[%key:common::config_flow::abort::already_configured_account%]", "external_error": "Exception occurred from another flow.", "external_setup": "Logi Circle successfully configured from another flow.", - "no_flows": "You need to configure Logi Circle before being able to authenticate with it. [Please read the instructions](https://www.home-assistant.io/components/logi_circle/)." + "missing_configuration": "[%key:common::config_flow::abort::oauth2_missing_configuration%]" } } } diff --git a/tests/components/logi_circle/test_config_flow.py b/tests/components/logi_circle/test_config_flow.py index 43dea15f7e6..c743cce7519 100644 --- a/tests/components/logi_circle/test_config_flow.py +++ b/tests/components/logi_circle/test_config_flow.py @@ -116,7 +116,7 @@ async def test_abort_if_no_implementation_registered(hass): result = await flow.async_step_user() assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "no_flows" + assert result["reason"] == "missing_configuration" async def test_abort_if_already_setup(hass): @@ -126,17 +126,17 @@ async def test_abort_if_already_setup(hass): with patch.object(hass.config_entries, "async_entries", return_value=[{}]): result = await flow.async_step_user() assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "already_setup" + assert result["reason"] == "already_configured" with patch.object(hass.config_entries, "async_entries", return_value=[{}]): result = await flow.async_step_import() assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "already_setup" + assert result["reason"] == "already_configured" with patch.object(hass.config_entries, "async_entries", return_value=[{}]): result = await flow.async_step_code() assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "already_setup" + assert result["reason"] == "already_configured" with patch.object(hass.config_entries, "async_entries", return_value=[{}]): result = await flow.async_step_auth() @@ -146,7 +146,10 @@ async def test_abort_if_already_setup(hass): @pytest.mark.parametrize( "side_effect,error", - [(asyncio.TimeoutError, "auth_timeout"), (AuthorizationFailed, "auth_error")], + [ + (asyncio.TimeoutError, "authorize_url_timeout"), + (AuthorizationFailed, "invalid_auth"), + ], ) async def test_abort_if_authorize_fails( hass, mock_logi_circle, side_effect, error