Skip to content

Commit

Permalink
Added debug around readuntil to detect deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdelprete committed Feb 13, 2024
1 parent 4f787a4 commit f567cda
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions custom_components/4noks_elios4you/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import asyncio
import logging
import socket
from datetime import datetime

import telnetlib3

Expand Down Expand Up @@ -177,9 +178,7 @@ async def async_get_data(self):
_LOGGER.debug(f"An error occurred: {str(e)}")

finally:
if not writer.transport.is_closing():
writer.close()
# await writer.wait_closed()
reader.feed_eof()
else:
_LOGGER.debug("Elios4you not ready for telnet connection")
raise ConnectionError(f"Elios4you not active on {self._host}:{self._port}")
Expand All @@ -194,7 +193,9 @@ async def telnet_get_data(self, cmd, reader, writer):
# send the command
writer.write(cmd + "\n")
# read stream up to the "ready..." string
_LOGGER.debug(f"telnet_get_data: readuntil started at {datetime.now()}")
response = await reader.readuntil(b"ready...")
_LOGGER.debug(f"telnet_get_data: readuntil ended at {datetime.now()}")
# decode bytes to string using utf-8 and split each line as a list member
lines = response.decode("utf-8").splitlines()
# _LOGGER.debug(f"telnet_get_data: lines {lines}")
Expand Down

0 comments on commit f567cda

Please sign in to comment.