diff --git a/aioesphomeapi/connection.py b/aioesphomeapi/connection.py index f8d562e..b97565c 100644 --- a/aioesphomeapi/connection.py +++ b/aioesphomeapi/connection.py @@ -373,12 +373,12 @@ class APIConnection: aiohappyeyeballs.pop_addr_infos_interleave(addr_infos, interleave) if sock is None: - if isinstance(last_exception, OSError): - raise SocketAPIError( - f"Error connecting to {addr_infos}: {last_exception}" + if isinstance(last_exception, asyncio_TimeoutError): + raise TimeoutAPIError( + f"Timeout while connecting to {addrs}" ) from last_exception raise SocketAPIError( - f"Timeout while connecting to {addr_infos}" + f"Error connecting to {addrs}: {last_exception}" ) from last_exception self._socket = sock diff --git a/tests/conftest.py b/tests/conftest.py index 45d46a0..35bb264 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -39,12 +39,14 @@ def async_zeroconf(): @pytest.fixture def resolve_host(): with patch("aioesphomeapi.host_resolver.async_resolve_host") as func: - func.return_value = AddrInfo( - family=socket.AF_INET, - type=socket.SOCK_STREAM, - proto=socket.IPPROTO_TCP, - sockaddr=IPv4Sockaddr("10.0.0.512", 6052), - ) + func.return_value = [ + AddrInfo( + family=socket.AF_INET, + type=socket.SOCK_STREAM, + proto=socket.IPPROTO_TCP, + sockaddr=IPv4Sockaddr("10.0.0.512", 6052), + ) + ] yield func