Use common strings in opentherm_gw config flow (#42211)

* Use common strings in opentherm_gw config flow

* Combine TimeourError and SerialException handling

* Fixed test_form_connection_error

* And then fix the flake8 error...

* Change "timeout" to "cannot_connect" msg
This commit is contained in:
wouterbaake 2020-10-25 22:01:05 +01:00 committed by GitHub
parent de12ac354a
commit e6400fc11b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 9 deletions

View File

@ -58,10 +58,8 @@ class OpenThermGwConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
try: try:
res = await asyncio.wait_for(test_connection(), timeout=10) res = await asyncio.wait_for(test_connection(), timeout=10)
except asyncio.TimeoutError: except (asyncio.TimeoutError, SerialException):
return self._show_form({"base": "timeout"}) return self._show_form({"base": "cannot_connect"})
except SerialException:
return self._show_form({"base": "serial_error"})
if res: if res:
return self._create_entry(gw_id, name, device) return self._create_entry(gw_id, name, device)

View File

@ -11,10 +11,9 @@
} }
}, },
"error": { "error": {
"already_configured": "Gateway already configured", "already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"id_exists": "Gateway id already exists", "id_exists": "Gateway id already exists",
"serial_error": "Error connecting to device", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
"timeout": "Connection attempt timed out"
} }
}, },
"options": { "options": {

View File

@ -148,7 +148,7 @@ async def test_form_connection_timeout(hass):
) )
assert result2["type"] == "form" assert result2["type"] == "form"
assert result2["errors"] == {"base": "timeout"} assert result2["errors"] == {"base": "cannot_connect"}
assert len(mock_connect.mock_calls) == 1 assert len(mock_connect.mock_calls) == 1
@ -164,7 +164,7 @@ async def test_form_connection_error(hass):
) )
assert result2["type"] == "form" assert result2["type"] == "form"
assert result2["errors"] == {"base": "serial_error"} assert result2["errors"] == {"base": "cannot_connect"}
assert len(mock_connect.mock_calls) == 1 assert len(mock_connect.mock_calls) == 1