From 3711d54ffa6affdb2fa2a35e4c9ef30aa163d71b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 Nov 2023 08:44:25 -0600 Subject: [PATCH] Add test for trying to finish an unstarted connection (#706) --- aioesphomeapi/connection.py | 2 +- tests/test_connection.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/aioesphomeapi/connection.py b/aioesphomeapi/connection.py index 9131a09..0d836c4 100644 --- a/aioesphomeapi/connection.py +++ b/aioesphomeapi/connection.py @@ -568,7 +568,7 @@ class APIConnection: than starts the keep alive process. """ if self.connection_state is not ConnectionState.SOCKET_OPENED: - raise ValueError( + raise RuntimeError( "Connection must be in SOCKET_OPENED state to finish connection" ) finish_connect_task = asyncio.create_task( diff --git a/tests/test_connection.py b/tests/test_connection.py index 16e6e8c..8cb58f1 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -784,3 +784,12 @@ async def test_connection_cannot_be_reused( await connect_task with pytest.raises(RuntimeError): await conn.start_connection() + + +@pytest.mark.asyncio +async def test_attempting_to_finish_unstarted_connection( + conn: APIConnection, +) -> None: + """Test that we raise when trying to finish an unstarted connection.""" + with pytest.raises(RuntimeError): + await conn.finish_connection(login=False)