mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Catch TimeoutError
in Brother
config flow (#113593)
* Catch TimeoutError in Brother config flow * Update tests * Remove unnecessary parentheses --------- Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
This commit is contained in:
parent
ef0c17749f
commit
6191b25563
@ -59,7 +59,7 @@ class BrotherConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return self.async_create_entry(title=title, data=user_input)
|
||||
except InvalidHost:
|
||||
errors[CONF_HOST] = "wrong_host"
|
||||
except ConnectionError:
|
||||
except (ConnectionError, TimeoutError):
|
||||
errors["base"] = "cannot_connect"
|
||||
except SnmpError:
|
||||
errors["base"] = "snmp_error"
|
||||
@ -89,7 +89,7 @@ class BrotherConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
await self.brother.async_update()
|
||||
except UnsupportedModelError:
|
||||
return self.async_abort(reason="unsupported_model")
|
||||
except (ConnectionError, SnmpError):
|
||||
except (ConnectionError, SnmpError, TimeoutError):
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
|
||||
# Check if already configured
|
||||
|
@ -94,10 +94,11 @@ async def test_invalid_hostname(hass: HomeAssistant) -> None:
|
||||
assert result["errors"] == {CONF_HOST: "wrong_host"}
|
||||
|
||||
|
||||
async def test_connection_error(hass: HomeAssistant) -> None:
|
||||
@pytest.mark.parametrize("exc", [ConnectionError, TimeoutError])
|
||||
async def test_connection_error(hass: HomeAssistant, exc: Exception) -> None:
|
||||
"""Test connection to host error."""
|
||||
with patch("brother.Brother.initialize"), patch(
|
||||
"brother.Brother._get_data", side_effect=ConnectionError()
|
||||
"brother.Brother._get_data", side_effect=exc
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG
|
||||
@ -148,10 +149,11 @@ async def test_device_exists_abort(hass: HomeAssistant) -> None:
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_zeroconf_snmp_error(hass: HomeAssistant) -> None:
|
||||
"""Test we abort zeroconf flow on SNMP error."""
|
||||
@pytest.mark.parametrize("exc", [ConnectionError, TimeoutError, SnmpError("error")])
|
||||
async def test_zeroconf_exception(hass: HomeAssistant, exc: Exception) -> None:
|
||||
"""Test we abort zeroconf flow on exception."""
|
||||
with patch("brother.Brother.initialize"), patch(
|
||||
"brother.Brother._get_data", side_effect=SnmpError("error")
|
||||
"brother.Brother._get_data", side_effect=exc
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
|
Loading…
x
Reference in New Issue
Block a user