Use common strings in Nest config flow (#41597)

This commit is contained in:
Christian Bilevits 2020-10-11 14:47:30 +02:00 committed by GitHub
parent ef448f1549
commit 1c4512bc40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 15 deletions

View file

@ -66,10 +66,10 @@ class NestFlowHandler(config_entries.ConfigFlow):
flows = self.hass.data.get(DATA_FLOW_IMPL, {}) flows = self.hass.data.get(DATA_FLOW_IMPL, {})
if self.hass.config_entries.async_entries(DOMAIN): 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: if not flows:
return self.async_abort(reason="no_flows") return self.async_abort(reason="missing_configuration")
if len(flows) == 1: if len(flows) == 1:
self.flow_impl = list(flows)[0] self.flow_impl = list(flows)[0]
@ -106,7 +106,7 @@ class NestFlowHandler(config_entries.ConfigFlow):
except asyncio.TimeoutError: except asyncio.TimeoutError:
errors["code"] = "timeout" errors["code"] = "timeout"
except CodeInvalid: except CodeInvalid:
errors["code"] = "invalid_code" errors["code"] = "invalid_pin"
except NestAuthError: except NestAuthError:
errors["code"] = "unknown" errors["code"] = "unknown"
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
@ -132,7 +132,7 @@ class NestFlowHandler(config_entries.ConfigFlow):
async def async_step_import(self, info): async def async_step_import(self, info):
"""Import existing auth from Nest.""" """Import existing auth from Nest."""
if self.hass.config_entries.async_entries(DOMAIN): 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"] config_path = info["nest_conf_path"]

View file

@ -3,25 +3,25 @@
"step": { "step": {
"init": { "init": {
"title": "Authentication Provider", "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" } "data": { "flow_impl": "Provider" }
}, },
"link": { "link": {
"title": "Link Nest Account", "title": "Link Nest Account",
"description": "To link your Nest account, [authorize your account]({url}).\n\nAfter authorization, copy-paste the provided pin code below.", "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": { "error": {
"timeout": "Timeout validating code", "timeout": "Timeout validating code",
"invalid_code": "Invalid code", "invalid_pin": "Invalid [%key:common::config_flow::data::pin%]",
"unknown": "Unknown error validating code", "unknown": "[%key:common::config_flow::error::unknown%]",
"internal_error": "Internal error validating code" "internal_error": "Internal error validating code"
}, },
"abort": { "abort": {
"already_setup": "You can only configure a single Nest account.", "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
"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/).", "missing_configuration": "[%key:common::config_flow::abort::oauth2_missing_configuration%]",
"authorize_url_timeout": "Timeout generating authorize url.", "authorize_url_timeout": "[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]",
"authorize_url_fail": "Unknown error generating an authorize url." "authorize_url_fail": "Unknown error generating an authorize url."
} }
} }

View file

@ -17,10 +17,10 @@ async def test_abort_if_no_implementation_registered(hass):
result = await flow.async_step_init() result = await flow.async_step_init()
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT 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.""" """Test we abort if Nest is already setup."""
flow = config_flow.NestFlowHandler() flow = config_flow.NestFlowHandler()
flow.hass = hass flow.hass = hass
@ -29,7 +29,7 @@ async def test_abort_if_already_setup(hass):
result = await flow.async_step_init() result = await flow.async_step_init()
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT 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): 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"}) result = await flow.async_step_link({"code": "123ABC"})
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "link" 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): async def test_verify_code_unknown_error(hass):