mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2025-02-21 02:33:22 +01:00
Fix wrapping native RequiresEncryption error types (#113)
This commit is contained in:
parent
e422847861
commit
06806b4490
@ -584,9 +584,10 @@ class APIConnection:
|
||||
|
||||
def on_read_exception(exc: Exception) -> None:
|
||||
if not fut.done():
|
||||
# Wrap error so that caller gets right stacktrace
|
||||
new_exc = ReadFailedAPIError("Read failed")
|
||||
new_exc.__cause__ = exc
|
||||
new_exc = exc
|
||||
if not isinstance(exc, APIConnectionError):
|
||||
new_exc = ReadFailedAPIError("Read failed")
|
||||
new_exc.__cause__ = exc
|
||||
fut.set_exception(new_exc)
|
||||
|
||||
self._message_handlers.append(on_message)
|
||||
|
@ -5,8 +5,8 @@ import pytest
|
||||
from mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
from aioesphomeapi.api_pb2 import ConnectResponse, HelloResponse
|
||||
from aioesphomeapi.connection import APIConnection, ConnectionParams
|
||||
from aioesphomeapi.core import APIConnectionError
|
||||
from aioesphomeapi.connection import APIConnection, ConnectionParams, ConnectionState
|
||||
from aioesphomeapi.core import APIConnectionError, RequiresEncryptionAPIError
|
||||
from aioesphomeapi.host_resolver import AddrInfo, IPv4Sockaddr
|
||||
|
||||
|
||||
@ -62,3 +62,18 @@ async def test_connect(conn, resolve_host, socket_socket, event_loop):
|
||||
await conn.connect()
|
||||
|
||||
assert conn.is_connected
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_requires_encryption_propagates(conn):
|
||||
with patch("asyncio.open_connection") as openc:
|
||||
reader = MagicMock()
|
||||
writer = MagicMock()
|
||||
openc.return_value = (reader, writer)
|
||||
writer.drain = AsyncMock()
|
||||
reader.readexactly = AsyncMock()
|
||||
reader.readexactly.return_value = b"\x01"
|
||||
|
||||
await conn._connect_init_frame_helper()
|
||||
with pytest.raises(RequiresEncryptionAPIError):
|
||||
await conn._connect_hello()
|
||||
|
Loading…
Reference in New Issue
Block a user