Make force_disconnect a normal function (#705)
This commit is contained in:
parent
402d6fe113
commit
3abf9ff8d4
|
@ -360,7 +360,7 @@ class APIClient:
|
||||||
if self._connection is None:
|
if self._connection is None:
|
||||||
return
|
return
|
||||||
if force:
|
if force:
|
||||||
await self._connection.force_disconnect()
|
self._connection.force_disconnect()
|
||||||
else:
|
else:
|
||||||
await self._connection.disconnect()
|
await self._connection.disconnect()
|
||||||
|
|
||||||
|
|
|
@ -915,7 +915,7 @@ class APIConnection:
|
||||||
|
|
||||||
self._cleanup()
|
self._cleanup()
|
||||||
|
|
||||||
async def force_disconnect(self) -> None:
|
def force_disconnect(self) -> None:
|
||||||
"""Forcefully disconnect from the API."""
|
"""Forcefully disconnect from the API."""
|
||||||
self._expected_disconnect = True
|
self._expected_disconnect = True
|
||||||
if self._handshake_complete:
|
if self._handshake_complete:
|
||||||
|
|
|
@ -1386,3 +1386,18 @@ async def test_set_debug(
|
||||||
mock_data_received(protocol, generate_plaintext_packet(response))
|
mock_data_received(protocol, generate_plaintext_packet(response))
|
||||||
await device_info_task
|
await device_info_task
|
||||||
assert "My Device" not in caplog.text
|
assert "My Device" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_force_disconnect(
|
||||||
|
api_client: tuple[
|
||||||
|
APIClient, APIConnection, asyncio.Transport, APIPlaintextFrameHelper
|
||||||
|
],
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
) -> None:
|
||||||
|
"""Test force disconnect can be called multiple times."""
|
||||||
|
client, connection, transport, protocol = api_client
|
||||||
|
await client.disconnect(force=True)
|
||||||
|
assert connection.is_connected is False
|
||||||
|
await client.disconnect(force=False)
|
||||||
|
assert connection.is_connected is False
|
||||||
|
|
|
@ -206,7 +206,7 @@ async def test_plaintext_connection(
|
||||||
assert isinstance(messages[1], DeviceInfoResponse)
|
assert isinstance(messages[1], DeviceInfoResponse)
|
||||||
assert messages[1].name == "m5stackatomproxy"
|
assert messages[1].name == "m5stackatomproxy"
|
||||||
remove()
|
remove()
|
||||||
await conn.force_disconnect()
|
conn.force_disconnect()
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ async def test_finish_connection_times_out(
|
||||||
|
|
||||||
assert not conn.is_connected
|
assert not conn.is_connected
|
||||||
remove()
|
remove()
|
||||||
await conn.force_disconnect()
|
conn.force_disconnect()
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -440,7 +440,7 @@ async def test_plaintext_connection_fails_handshake(
|
||||||
assert isinstance(messages[1], DeviceInfoResponse)
|
assert isinstance(messages[1], DeviceInfoResponse)
|
||||||
assert messages[1].name == "m5stackatomproxy"
|
assert messages[1].name == "m5stackatomproxy"
|
||||||
remove()
|
remove()
|
||||||
await conn.force_disconnect()
|
conn.force_disconnect()
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -493,7 +493,7 @@ async def test_force_disconnect_fails(
|
||||||
assert conn.is_connected
|
assert conn.is_connected
|
||||||
|
|
||||||
with patch.object(protocol, "_writer", side_effect=OSError):
|
with patch.object(protocol, "_writer", side_effect=OSError):
|
||||||
await conn.force_disconnect()
|
conn.force_disconnect()
|
||||||
assert "Failed to send (forced) disconnect request" in caplog.text
|
assert "Failed to send (forced) disconnect request" in caplog.text
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
|
|
||||||
|
@ -737,7 +737,7 @@ async def test_unknown_protobuf_message_type_logged(
|
||||||
|
|
||||||
assert "Skipping unknown message type 16385" in caplog.text
|
assert "Skipping unknown message type 16385" in caplog.text
|
||||||
assert connection.is_connected
|
assert connection.is_connected
|
||||||
await connection.force_disconnect()
|
connection.force_disconnect()
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue