diff --git a/homeassistant/components/emulated_kasa/manifest.json b/homeassistant/components/emulated_kasa/manifest.json index c11fecb3ff1..c7f9175bc5e 100644 --- a/homeassistant/components/emulated_kasa/manifest.json +++ b/homeassistant/components/emulated_kasa/manifest.json @@ -2,7 +2,7 @@ "domain": "emulated_kasa", "name": "Emulated Kasa", "documentation": "https://www.home-assistant.io/integrations/emulated_kasa", - "requirements": ["sense_energy==0.10.2"], + "requirements": ["sense_energy==0.10.3"], "codeowners": ["@kbickar"], "quality_scale": "internal", "iot_class": "local_push", diff --git a/homeassistant/components/sense/config_flow.py b/homeassistant/components/sense/config_flow.py index eea36424662..8769d4cb83f 100644 --- a/homeassistant/components/sense/config_flow.py +++ b/homeassistant/components/sense/config_flow.py @@ -12,7 +12,7 @@ from homeassistant import config_entries from homeassistant.const import CONF_CODE, CONF_EMAIL, CONF_PASSWORD, CONF_TIMEOUT from homeassistant.helpers.aiohttp_client import async_get_clientsession -from .const import ACTIVE_UPDATE_RATE, DEFAULT_TIMEOUT, DOMAIN, SENSE_TIMEOUT_EXCEPTIONS +from .const import ACTIVE_UPDATE_RATE, DEFAULT_TIMEOUT, DOMAIN, SENSE_CONNECT_EXCEPTIONS _LOGGER = logging.getLogger(__name__) @@ -76,7 +76,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): await self.validate_input(user_input) except SenseMFARequiredException: return await self.async_step_validation() - except SENSE_TIMEOUT_EXCEPTIONS: + except SENSE_CONNECT_EXCEPTIONS: errors["base"] = "cannot_connect" except SenseAuthenticationException: errors["base"] = "invalid_auth" @@ -93,7 +93,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): if user_input: try: await self._gateway.validate_mfa(user_input[CONF_CODE]) - except SENSE_TIMEOUT_EXCEPTIONS: + except SENSE_CONNECT_EXCEPTIONS: errors["base"] = "cannot_connect" except SenseAuthenticationException: errors["base"] = "invalid_auth" diff --git a/homeassistant/components/sense/const.py b/homeassistant/components/sense/const.py index bb323151950..622e9897a66 100644 --- a/homeassistant/components/sense/const.py +++ b/homeassistant/components/sense/const.py @@ -3,8 +3,11 @@ import asyncio import socket -from sense_energy import SenseAPITimeoutException -from sense_energy.sense_exceptions import SenseWebsocketException +from sense_energy import ( + SenseAPIException, + SenseAPITimeoutException, + SenseWebsocketException, +) DOMAIN = "sense" DEFAULT_TIMEOUT = 10 @@ -40,6 +43,11 @@ ICON = "mdi:flash" SENSE_TIMEOUT_EXCEPTIONS = (asyncio.TimeoutError, SenseAPITimeoutException) SENSE_EXCEPTIONS = (socket.gaierror, SenseWebsocketException) +SENSE_CONNECT_EXCEPTIONS = ( + asyncio.TimeoutError, + SenseAPITimeoutException, + SenseAPIException, +) MDI_ICONS = { "ac": "air-conditioner", diff --git a/homeassistant/components/sense/manifest.json b/homeassistant/components/sense/manifest.json index 30de722a7bc..04b0b451db4 100644 --- a/homeassistant/components/sense/manifest.json +++ b/homeassistant/components/sense/manifest.json @@ -2,7 +2,7 @@ "domain": "sense", "name": "Sense", "documentation": "https://www.home-assistant.io/integrations/sense", - "requirements": ["sense_energy==0.10.2"], + "requirements": ["sense_energy==0.10.3"], "codeowners": ["@kbickar"], "config_flow": true, "dhcp": [ diff --git a/requirements_all.txt b/requirements_all.txt index 0cb4a718af6..33f282fba67 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2118,7 +2118,7 @@ sendgrid==6.8.2 # homeassistant.components.emulated_kasa # homeassistant.components.sense -sense_energy==0.10.2 +sense_energy==0.10.3 # homeassistant.components.sentry sentry-sdk==1.5.8 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 2e905d2a194..4dd9485f930 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1352,7 +1352,7 @@ securetar==2022.2.0 # homeassistant.components.emulated_kasa # homeassistant.components.sense -sense_energy==0.10.2 +sense_energy==0.10.3 # homeassistant.components.sentry sentry-sdk==1.5.8 diff --git a/tests/components/sense/test_config_flow.py b/tests/components/sense/test_config_flow.py index f939142aee4..690e5d2e530 100644 --- a/tests/components/sense/test_config_flow.py +++ b/tests/components/sense/test_config_flow.py @@ -3,6 +3,7 @@ from unittest.mock import AsyncMock, patch import pytest from sense_energy import ( + SenseAPIException, SenseAPITimeoutException, SenseAuthenticationException, SenseMFARequiredException, @@ -189,7 +190,7 @@ async def test_form_mfa_required_exception(hass, mock_sense): assert result3["errors"] == {"base": "unknown"} -async def test_form_cannot_connect(hass): +async def test_form_timeout(hass): """Test we handle cannot connect error.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -208,6 +209,25 @@ async def test_form_cannot_connect(hass): assert result2["errors"] == {"base": "cannot_connect"} +async def test_form_cannot_connect(hass): + """Test we handle cannot connect error.""" + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + + with patch( + "sense_energy.ASyncSenseable.authenticate", + side_effect=SenseAPIException, + ): + result2 = await hass.config_entries.flow.async_configure( + result["flow_id"], + {"timeout": "6", "email": "test-email", "password": "test-password"}, + ) + + assert result2["type"] == "form" + assert result2["errors"] == {"base": "cannot_connect"} + + async def test_form_unknown_exception(hass): """Test we handle unknown error.""" result = await hass.config_entries.flow.async_init(