diff --git a/homeassistant/components/honeywell/__init__.py b/homeassistant/components/honeywell/__init__.py index 8349c383e9f..5a4d6374304 100644 --- a/homeassistant/components/honeywell/__init__.py +++ b/homeassistant/components/honeywell/__init__.py @@ -2,6 +2,7 @@ from dataclasses import dataclass +from aiohttp.client_exceptions import ClientConnectionError import aiosomecomfort from homeassistant.config_entries import ConfigEntry @@ -68,6 +69,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b aiosomecomfort.device.ConnectionError, aiosomecomfort.device.ConnectionTimeout, aiosomecomfort.device.SomeComfortError, + ClientConnectionError, TimeoutError, ) as ex: raise ConfigEntryNotReady( diff --git a/homeassistant/components/honeywell/config_flow.py b/homeassistant/components/honeywell/config_flow.py index 809fa45449b..7f298aee632 100644 --- a/homeassistant/components/honeywell/config_flow.py +++ b/homeassistant/components/honeywell/config_flow.py @@ -54,6 +54,7 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN): """Confirm re-authentication with Honeywell.""" errors: dict[str, str] = {} assert self.entry is not None + if user_input: try: await self.is_valid( @@ -63,14 +64,12 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN): except aiosomecomfort.AuthError: errors["base"] = "invalid_auth" - except ( aiosomecomfort.ConnectionError, aiosomecomfort.ConnectionTimeout, TimeoutError, ): errors["base"] = "cannot_connect" - else: return self.async_update_reload_and_abort( self.entry, @@ -83,7 +82,8 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN): return self.async_show_form( step_id="reauth_confirm", data_schema=self.add_suggested_values_to_schema( - REAUTH_SCHEMA, self.entry.data + REAUTH_SCHEMA, + self.entry.data, ), errors=errors, description_placeholders={"name": "Honeywell"}, @@ -91,7 +91,7 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN): async def async_step_user(self, user_input=None) -> ConfigFlowResult: """Create config entry. Show the setup form to the user.""" - errors = {} + errors: dict[str, str] = {} if user_input is not None: try: await self.is_valid(**user_input) @@ -103,7 +103,6 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN): TimeoutError, ): errors["base"] = "cannot_connect" - if not errors: return self.async_create_entry( title=DOMAIN, @@ -115,7 +114,9 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN): vol.Required(CONF_PASSWORD): str, } return self.async_show_form( - step_id="user", data_schema=vol.Schema(data_schema), errors=errors + step_id="user", + data_schema=vol.Schema(data_schema), + errors=errors, ) async def is_valid(self, **kwargs) -> bool: diff --git a/tests/components/honeywell/test_init.py b/tests/components/honeywell/test_init.py index a77c0aaed7e..cdd767f019d 100644 --- a/tests/components/honeywell/test_init.py +++ b/tests/components/honeywell/test_init.py @@ -2,6 +2,7 @@ from unittest.mock import MagicMock, create_autospec, patch +from aiohttp.client_exceptions import ClientConnectionError import aiosomecomfort import pytest @@ -120,11 +121,23 @@ async def test_login_error( assert config_entry.state is ConfigEntryState.SETUP_ERROR +@pytest.mark.parametrize( + "the_error", + [ + aiosomecomfort.ConnectionError, + aiosomecomfort.device.ConnectionTimeout, + aiosomecomfort.device.SomeComfortError, + ClientConnectionError, + ], +) async def test_connection_error( - hass: HomeAssistant, client: MagicMock, config_entry: MagicMock + hass: HomeAssistant, + client: MagicMock, + config_entry: MagicMock, + the_error: Exception, ) -> None: """Test Connection errors from API.""" - client.login.side_effect = aiosomecomfort.ConnectionError + client.login.side_effect = the_error await init_integration(hass, config_entry) assert config_entry.state is ConfigEntryState.SETUP_RETRY