mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
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 <marhje52@gmail.com>
This commit is contained in:
parent
ae20b3a678
commit
9d6589240f
@ -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"]
|
||||
|
@ -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%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user