Skip to content

Commit

Permalink
finally fixed cmd and separator types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdelprete committed Feb 14, 2024
1 parent da19ae9 commit 53d0b5d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions custom_components/4noks_elios4you/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(
self._name = name
self._host = host
self._port = port
self._timeout = 10
self._timeout = 5
self._sensors = []
self.data = {}
# Initialize Elios4You data structure before first read
Expand Down Expand Up @@ -209,15 +209,24 @@ async def async_get_data(self):
async def telnet_get_data(self, cmd, reader, writer):
"""Send Telnet Commands and process output."""
try:
cmd = cmd.lower() + "\n"
cmd_main = cmd[0:4]
_LOGGER.debug(f"telnet_get_data: cmd {cmd} cmd_main: {cmd_main}")
# cmd for telnetlib3.stream_writer.write()
# string with LF
cmd_send = cmd.lower() + "\n"
# separator for telnetlib3.stream_reader.readuntil()
# byte encoded string
separator = bytes("ready...", "utf-8")
# get only command part without parameters
cmd_main = cmd[0:4].lower()
response = None
output = {}

_LOGGER.debug(
f"telnet_get_data: cmd {cmd} cmd_send: {cmd_send} cmd_main: {cmd_main}"
)

# send the command
_LOGGER.debug(f"telnet_get_data: before write {datetime.now()}")
writer.write(cmd)
writer.write(cmd_send)
_LOGGER.debug(f"telnet_get_data: after write {datetime.now()}")

# read stream up to the "ready..." string
Expand All @@ -227,7 +236,7 @@ async def telnet_get_data(self, cmd, reader, writer):
# sometimes telnetlib3 hangs on readuntil so we manage a timeout
try:
response = await asyncio.wait_for(
reader.readuntil(b"ready..."), timeout=self._timeout
reader.readuntil(separator), timeout=self._timeout
)
except IncompleteReadError as ex:
_LOGGER.debug(
Expand Down

0 comments on commit 53d0b5d

Please sign in to comment.