Add coverage for BLE connection drop during pairing (#746)

This commit is contained in:
J. Nick Koston 2023-11-26 17:11:42 -06:00 committed by GitHub
parent a148479679
commit 3ff5f876d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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[