mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Catch client connection error in Honeywell (#117502)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
bb0b01e4a9
commit
5c263b039e
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from aiohttp.client_exceptions import ClientConnectionError
|
||||||
import aiosomecomfort
|
import aiosomecomfort
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.ConnectionError,
|
||||||
aiosomecomfort.device.ConnectionTimeout,
|
aiosomecomfort.device.ConnectionTimeout,
|
||||||
aiosomecomfort.device.SomeComfortError,
|
aiosomecomfort.device.SomeComfortError,
|
||||||
|
ClientConnectionError,
|
||||||
TimeoutError,
|
TimeoutError,
|
||||||
) as ex:
|
) as ex:
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
|
@ -54,6 +54,7 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Confirm re-authentication with Honeywell."""
|
"""Confirm re-authentication with Honeywell."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
assert self.entry is not None
|
assert self.entry is not None
|
||||||
|
|
||||||
if user_input:
|
if user_input:
|
||||||
try:
|
try:
|
||||||
await self.is_valid(
|
await self.is_valid(
|
||||||
@ -63,14 +64,12 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
except aiosomecomfort.AuthError:
|
except aiosomecomfort.AuthError:
|
||||||
errors["base"] = "invalid_auth"
|
errors["base"] = "invalid_auth"
|
||||||
|
|
||||||
except (
|
except (
|
||||||
aiosomecomfort.ConnectionError,
|
aiosomecomfort.ConnectionError,
|
||||||
aiosomecomfort.ConnectionTimeout,
|
aiosomecomfort.ConnectionTimeout,
|
||||||
TimeoutError,
|
TimeoutError,
|
||||||
):
|
):
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self.entry,
|
self.entry,
|
||||||
@ -83,7 +82,8 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
data_schema=self.add_suggested_values_to_schema(
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
REAUTH_SCHEMA, self.entry.data
|
REAUTH_SCHEMA,
|
||||||
|
self.entry.data,
|
||||||
),
|
),
|
||||||
errors=errors,
|
errors=errors,
|
||||||
description_placeholders={"name": "Honeywell"},
|
description_placeholders={"name": "Honeywell"},
|
||||||
@ -91,7 +91,7 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_user(self, user_input=None) -> ConfigFlowResult:
|
async def async_step_user(self, user_input=None) -> ConfigFlowResult:
|
||||||
"""Create config entry. Show the setup form to the user."""
|
"""Create config entry. Show the setup form to the user."""
|
||||||
errors = {}
|
errors: dict[str, str] = {}
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
try:
|
try:
|
||||||
await self.is_valid(**user_input)
|
await self.is_valid(**user_input)
|
||||||
@ -103,7 +103,6 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
TimeoutError,
|
TimeoutError,
|
||||||
):
|
):
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=DOMAIN,
|
title=DOMAIN,
|
||||||
@ -115,7 +114,9 @@ class HoneywellConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
vol.Required(CONF_PASSWORD): str,
|
vol.Required(CONF_PASSWORD): str,
|
||||||
}
|
}
|
||||||
return self.async_show_form(
|
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:
|
async def is_valid(self, **kwargs) -> bool:
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from unittest.mock import MagicMock, create_autospec, patch
|
from unittest.mock import MagicMock, create_autospec, patch
|
||||||
|
|
||||||
|
from aiohttp.client_exceptions import ClientConnectionError
|
||||||
import aiosomecomfort
|
import aiosomecomfort
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -120,11 +121,23 @@ async def test_login_error(
|
|||||||
assert config_entry.state is ConfigEntryState.SETUP_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(
|
async def test_connection_error(
|
||||||
hass: HomeAssistant, client: MagicMock, config_entry: MagicMock
|
hass: HomeAssistant,
|
||||||
|
client: MagicMock,
|
||||||
|
config_entry: MagicMock,
|
||||||
|
the_error: Exception,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test Connection errors from API."""
|
"""Test Connection errors from API."""
|
||||||
client.login.side_effect = aiosomecomfort.ConnectionError
|
client.login.side_effect = the_error
|
||||||
await init_integration(hass, config_entry)
|
await init_integration(hass, config_entry)
|
||||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user