mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-11-26 12:45:26 +01:00
Add coverage for BLE connection drop during pairing (#746)
This commit is contained in:
parent
a148479679
commit
3ff5f876d5
@ -640,7 +640,7 @@ class APIClient:
|
|||||||
return False
|
return False
|
||||||
if isinstance(msg, BluetoothDeviceConnectionResponse):
|
if isinstance(msg, BluetoothDeviceConnectionResponse):
|
||||||
raise APIConnectionError(
|
raise APIConnectionError(
|
||||||
"Peripheral changed connections status while pairing"
|
f"Peripheral changed connections status while pairing: {msg.error}"
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -912,6 +912,27 @@ async def test_bluetooth_pair(
|
|||||||
await pair_task
|
await pair_task
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_bluetooth_pair_connection_drops(
|
||||||
|
api_client: tuple[
|
||||||
|
APIClient, APIConnection, asyncio.Transport, APIPlaintextFrameHelper
|
||||||
|
],
|
||||||
|
) -> None:
|
||||||
|
"""Test connection drop during bluetooth_device_pair."""
|
||||||
|
client, connection, transport, protocol = api_client
|
||||||
|
pair_task = asyncio.create_task(client.bluetooth_device_pair(1234))
|
||||||
|
await asyncio.sleep(0)
|
||||||
|
response: message.Message = BluetoothDeviceConnectionResponse(
|
||||||
|
address=1234, connected=False, error=13
|
||||||
|
)
|
||||||
|
mock_data_received(protocol, generate_plaintext_packet(response))
|
||||||
|
with pytest.raises(
|
||||||
|
APIConnectionError,
|
||||||
|
match="Peripheral changed connections status while pairing: 13",
|
||||||
|
):
|
||||||
|
await pair_task
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_bluetooth_unpair(
|
async def test_bluetooth_unpair(
|
||||||
api_client: tuple[
|
api_client: tuple[
|
||||||
|
Loading…
Reference in New Issue
Block a user