From e6400fc11bc71c12ac345a630bdc144cc332f8ac Mon Sep 17 00:00:00 2001 From: wouterbaake Date: Sun, 25 Oct 2020 22:01:05 +0100 Subject: [PATCH] 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 --- homeassistant/components/opentherm_gw/config_flow.py | 6 ++---- homeassistant/components/opentherm_gw/strings.json | 5 ++--- tests/components/opentherm_gw/test_config_flow.py | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/opentherm_gw/config_flow.py b/homeassistant/components/opentherm_gw/config_flow.py index 4afc508b8ee..60d367db5a1 100644 --- a/homeassistant/components/opentherm_gw/config_flow.py +++ b/homeassistant/components/opentherm_gw/config_flow.py @@ -58,10 +58,8 @@ class OpenThermGwConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): try: res = await asyncio.wait_for(test_connection(), timeout=10) - except asyncio.TimeoutError: - return self._show_form({"base": "timeout"}) - except SerialException: - return self._show_form({"base": "serial_error"}) + except (asyncio.TimeoutError, SerialException): + return self._show_form({"base": "cannot_connect"}) if res: return self._create_entry(gw_id, name, device) diff --git a/homeassistant/components/opentherm_gw/strings.json b/homeassistant/components/opentherm_gw/strings.json index 332b97eb5ee..306529e7be1 100644 --- a/homeassistant/components/opentherm_gw/strings.json +++ b/homeassistant/components/opentherm_gw/strings.json @@ -11,10 +11,9 @@ } }, "error": { - "already_configured": "Gateway already configured", + "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", "id_exists": "Gateway id already exists", - "serial_error": "Error connecting to device", - "timeout": "Connection attempt timed out" + "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]" } }, "options": { diff --git a/tests/components/opentherm_gw/test_config_flow.py b/tests/components/opentherm_gw/test_config_flow.py index d2d31d97628..2f4c171cf36 100644 --- a/tests/components/opentherm_gw/test_config_flow.py +++ b/tests/components/opentherm_gw/test_config_flow.py @@ -148,7 +148,7 @@ async def test_form_connection_timeout(hass): ) assert result2["type"] == "form" - assert result2["errors"] == {"base": "timeout"} + assert result2["errors"] == {"base": "cannot_connect"} assert len(mock_connect.mock_calls) == 1 @@ -164,7 +164,7 @@ async def test_form_connection_error(hass): ) assert result2["type"] == "form" - assert result2["errors"] == {"base": "serial_error"} + assert result2["errors"] == {"base": "cannot_connect"} assert len(mock_connect.mock_calls) == 1