Use common strings for velbus config flow (#40660)

This commit is contained in:
Maikel Punie 2020-09-30 13:53:03 +02:00 committed by GitHub
parent 27350f41c9
commit 30effb5c8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View file

@ -37,7 +37,7 @@ class VelbusConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
try:
controller = velbus.Controller(prt)
except Exception: # pylint: disable=broad-except
self._errors[CONF_PORT] = "connection_failed"
self._errors[CONF_PORT] = "cannot_connect"
return False
controller.stop()
return True
@ -58,7 +58,7 @@ class VelbusConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
if self._test_connection(prt):
return self._create_device(name, prt)
else:
self._errors[CONF_PORT] = "port_exists"
self._errors[CONF_PORT] = "already_configured"
else:
user_input = {}
user_input[CONF_NAME] = ""
@ -82,5 +82,5 @@ class VelbusConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
if self._prt_in_configuration_exists(prt):
# if the velbus import is already in the config
# we should not proceed the import
return self.async_abort(reason="port_exists")
return self.async_abort(reason="already_configured")
return await self.async_step_user(user_input)

View file

@ -10,9 +10,11 @@
}
},
"error": {
"port_exists": "This port is already configured",
"connection_failed": "The velbus connection failed"
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
},
"abort": { "port_exists": "This port is already configured" }
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
}
}
}

View file

@ -65,13 +65,13 @@ async def test_user_fail(hass, controller_assert):
{CONF_NAME: "Velbus Test Serial", CONF_PORT: PORT_SERIAL}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["errors"] == {CONF_PORT: "connection_failed"}
assert result["errors"] == {CONF_PORT: "cannot_connect"}
result = await flow.async_step_user(
{CONF_NAME: "Velbus Test TCP", CONF_PORT: PORT_TCP}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["errors"] == {CONF_PORT: "connection_failed"}
assert result["errors"] == {CONF_PORT: "cannot_connect"}
async def test_import(hass, controller):
@ -94,10 +94,10 @@ async def test_abort_if_already_setup(hass):
{CONF_PORT: PORT_TCP, CONF_NAME: "velbus import test"}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "port_exists"
assert result["reason"] == "already_configured"
result = await flow.async_step_user(
{CONF_PORT: PORT_TCP, CONF_NAME: "velbus import test"}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["errors"] == {"port": "port_exists"}
assert result["errors"] == {"port": "already_configured"}