Use common strings for Mikrotik config flow (#41110)

This commit is contained in:
Spartan-II-117 2020-10-03 05:39:18 -07:00 committed by GitHub
parent cb8d7fe575
commit 3208670b61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 10 deletions

View File

@ -43,7 +43,7 @@ class MikrotikFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
if user_input is not None: if user_input is not None:
for entry in self.hass.config_entries.async_entries(DOMAIN): for entry in self.hass.config_entries.async_entries(DOMAIN):
if entry.data[CONF_HOST] == user_input[CONF_HOST]: if entry.data[CONF_HOST] == user_input[CONF_HOST]:
return self.async_abort(reason="already_configured") return self.async_abort(reason="already_configured_device")
if entry.data[CONF_NAME] == user_input[CONF_NAME]: if entry.data[CONF_NAME] == user_input[CONF_NAME]:
errors[CONF_NAME] = "name_exists" errors[CONF_NAME] = "name_exists"
break break
@ -53,8 +53,8 @@ class MikrotikFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
except CannotConnect: except CannotConnect:
errors["base"] = "cannot_connect" errors["base"] = "cannot_connect"
except LoginError: except LoginError:
errors[CONF_USERNAME] = "wrong_credentials" errors[CONF_USERNAME] = "invalid_auth"
errors[CONF_PASSWORD] = "wrong_credentials" errors[CONF_PASSWORD] = "invalid_auth"
if not errors: if not errors:
return self.async_create_entry( return self.async_create_entry(

View File

@ -15,11 +15,11 @@
}, },
"error": { "error": {
"name_exists": "Name exists", "name_exists": "Name exists",
"cannot_connect": "Connection Unsuccessful", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"wrong_credentials": "Wrong Credentials" "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
}, },
"abort": { "abort": {
"already_configured": "Mikrotik is already configured" "already_configured_device": "[%key:common::config_flow::abort::already_configured_device%]"
} }
}, },
"options": { "options": {
@ -33,4 +33,4 @@
} }
} }
} }
} }

View File

@ -156,7 +156,7 @@ async def test_host_already_configured(hass, auth_error):
result["flow_id"], user_input=DEMO_USER_INPUT result["flow_id"], user_input=DEMO_USER_INPUT
) )
assert result["type"] == "abort" assert result["type"] == "abort"
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured_device"
async def test_name_exists(hass, api): async def test_name_exists(hass, api):
@ -203,6 +203,6 @@ async def test_wrong_credentials(hass, auth_error):
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["errors"] == { assert result["errors"] == {
CONF_USERNAME: "wrong_credentials", CONF_USERNAME: "invalid_auth",
CONF_PASSWORD: "wrong_credentials", CONF_PASSWORD: "invalid_auth",
} }