Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions flashforge/tcp/tcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ def __init__(self, hostname: str) -> None:
self._keep_alive_errors = 0
"""Counter for consecutive keep-alive errors."""

self._socket_busy = False
"""Flag indicating if the socket is currently busy sending a command and awaiting a response."""

self._socket_lock = asyncio.Lock()
"""Lock to ensure only one command is sent at a time."""

Expand Down Expand Up @@ -130,15 +127,6 @@ async def stop_keep_alive(self, logout: bool = False) -> None:

logger.info("Keep-alive stopped.")

async def is_socket_busy(self) -> bool:
"""
Check if the socket is currently busy processing a command.

Returns:
True if the socket is busy, False otherwise
"""
return self._socket_busy

async def send_command_async(self, cmd: str) -> Optional[str]:
"""
Send a command string to the printer asynchronously via the TCP socket.
Expand All @@ -155,8 +143,6 @@ async def send_command_async(self, cmd: str) -> Optional[str]:
the reply is invalid, or the connection needs to be reset
"""
async with self._socket_lock:
self._socket_busy = True

logger.debug(f"sendCommand: {cmd}")
try:
await self._check_socket()
Expand All @@ -180,26 +166,6 @@ async def send_command_async(self, cmd: str) -> Optional[str]:
except Exception as error:
logger.error(f"Error while sending command: {error}")
return None
finally:
self._socket_busy = False

async def _wait_until_socket_available(self) -> None:
"""
Wait until the socket is no longer busy or a timeout is reached.

This is used to serialize commands sent over the socket.

Raises:
TimeoutError: If the socket remains busy for too long (10 seconds)
"""
max_wait_time = 10.0 # 10 seconds
start_time = asyncio.get_event_loop().time()

while self._socket_busy and (asyncio.get_event_loop().time() - start_time < max_wait_time):
await asyncio.sleep(0.1)

if self._socket_busy:
raise TimeoutError("Socket remained busy for too long, timing out")

async def _check_socket(self) -> None:
"""
Expand Down