Use common strings in Nest config flow (#41597)
parent
ef448f1549
commit
1c4512bc40
|
@ -66,10 +66,10 @@ class NestFlowHandler(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="single_instance_allowed")
|
||||
|
||||
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]
|
||||
|
@ -106,7 +106,7 @@ class NestFlowHandler(config_entries.ConfigFlow):
|
|||
except asyncio.TimeoutError:
|
||||
errors["code"] = "timeout"
|
||||
except CodeInvalid:
|
||||
errors["code"] = "invalid_code"
|
||||
errors["code"] = "invalid_pin"
|
||||
except NestAuthError:
|
||||
errors["code"] = "unknown"
|
||||
except Exception: # pylint: disable=broad-except
|
||||
|
@ -132,7 +132,7 @@ class NestFlowHandler(config_entries.ConfigFlow):
|
|||
async def async_step_import(self, info):
|
||||
"""Import existing auth from Nest."""
|
||||
if self.hass.config_entries.async_entries(DOMAIN):
|
||||
return self.async_abort(reason="already_setup")
|
||||
return self.async_abort(reason="single_instance_allowed")
|
||||
|
||||
config_path = info["nest_conf_path"]
|
||||
|
||||
|
|
|
@ -3,25 +3,25 @@
|
|||
"step": {
|
||||
"init": {
|
||||
"title": "Authentication Provider",
|
||||
"description": "Pick via which authentication provider you want to authenticate with Nest.",
|
||||
"description": "[%key:common::config_flow::title::oauth2_pick_implementation%]",
|
||||
"data": { "flow_impl": "Provider" }
|
||||
},
|
||||
"link": {
|
||||
"title": "Link Nest Account",
|
||||
"description": "To link your Nest account, [authorize your account]({url}).\n\nAfter authorization, copy-paste the provided pin code below.",
|
||||
"data": { "code": "Pin code" }
|
||||
"data": { "code": "[%key:common::config_flow::data::pin%]" }
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"timeout": "Timeout validating code",
|
||||
"invalid_code": "Invalid code",
|
||||
"unknown": "Unknown error validating code",
|
||||
"invalid_pin": "Invalid [%key:common::config_flow::data::pin%]",
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]",
|
||||
"internal_error": "Internal error validating code"
|
||||
},
|
||||
"abort": {
|
||||
"already_setup": "You can only configure a single Nest account.",
|
||||
"no_flows": "You need to configure Nest before being able to authenticate with it. [Please read the instructions](https://www.home-assistant.io/components/nest/).",
|
||||
"authorize_url_timeout": "Timeout generating authorize url.",
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
|
||||
"missing_configuration": "[%key:common::config_flow::abort::oauth2_missing_configuration%]",
|
||||
"authorize_url_timeout": "[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]",
|
||||
"authorize_url_fail": "Unknown error generating an authorize url."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@ async def test_abort_if_no_implementation_registered(hass):
|
|||
result = await flow.async_step_init()
|
||||
|
||||
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):
|
||||
async def test_abort_if_single_instance_allowed(hass):
|
||||
"""Test we abort if Nest is already setup."""
|
||||
flow = config_flow.NestFlowHandler()
|
||||
flow.hass = hass
|
||||
|
@ -29,7 +29,7 @@ async def test_abort_if_already_setup(hass):
|
|||
result = await flow.async_step_init()
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_setup"
|
||||
assert result["reason"] == "single_instance_allowed"
|
||||
|
||||
|
||||
async def test_full_flow_implementation(hass):
|
||||
|
@ -140,7 +140,7 @@ async def test_verify_code_invalid(hass):
|
|||
result = await flow.async_step_link({"code": "123ABC"})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "link"
|
||||
assert result["errors"] == {"code": "invalid_code"}
|
||||
assert result["errors"] == {"code": "invalid_pin"}
|
||||
|
||||
|
||||
async def test_verify_code_unknown_error(hass):
|
||||
|
|
Loading…
Reference in New Issue