diff --git a/aioesphomeapi/client.py b/aioesphomeapi/client.py index ebdda1c..c78f2bb 100644 --- a/aioesphomeapi/client.py +++ b/aioesphomeapi/client.py @@ -640,7 +640,7 @@ class APIClient: return False if isinstance(msg, BluetoothDeviceConnectionResponse): raise APIConnectionError( - "Peripheral changed connections status while pairing" + f"Peripheral changed connections status while pairing: {msg.error}" ) return True diff --git a/tests/test_client.py b/tests/test_client.py index 2364c5c..0ee120d 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -912,6 +912,27 @@ async def test_bluetooth_pair( 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 async def test_bluetooth_unpair( api_client: tuple[