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
8 changes: 5 additions & 3 deletions custom_components/luxtronik2/lux_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ def _is_socket_closed(sock: socket.socket) -> bool:
last_timeout: float | None = None
try:
last_timeout = sock.gettimeout()
# this will try to read bytes without blocking and also without removing them from buffer (peek only)
sock.settimeout(None)
data = sock.recv(16, socket.MSG_DONTWAIT | socket.MSG_PEEK)
# settimeout(0) puts the socket in non-blocking mode (raises BlockingIOError
# instead of waiting), portably across platforms - socket.MSG_DONTWAIT is
# POSIX-only and unavailable on Windows. MSG_PEEK reads without consuming.
sock.settimeout(0)
data = sock.recv(16, socket.MSG_PEEK)
if len(data) == 0:
return True
except BlockingIOError:
Expand Down
Loading