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)