Skip to content

Commit

Permalink
* Fixed issue where login would stall on Honeywell systems if the EVL…
Browse files Browse the repository at this point in the history
…'s response to the login also included portions of the next command.

* Added a timeout in the read loop and adjusted some logging to help track down why things become unresponsive.
  • Loading branch information
ufodone committed Jan 15, 2023
1 parent be8f9fd commit 8c8b54f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,25 @@ async def read_loop(self):
unprocessed_data = None
while not self._shutdown and self._reader:
_LOGGER.debug("Waiting for data from EVL")
data = await self._reader.read(n=256)
try:
data = await asyncio.wait_for(self._reader.read(n=256), 5)
except asyncio.exceptions.TimeoutError:
continue

if not data or len(data) == 0 or self._reader.at_eof():
_LOGGER.error('The server closed the connection.')
await self.disconnect()
break

data = data.decode('ascii')
_LOGGER.debug('----------------------------------------')
_LOGGER.debug('{---------------------------------------')
_LOGGER.debug(str.format('RX < {0}', data))

if unprocessed_data:
data = unprocessed_data + data

unprocessed_data = self.process_data(data)
_LOGGER.debug('}---------------------------------------')
except Exception as ex:
_LOGGER.error("Caught unexpected exception: %r", ex)
await self.disconnect()
Expand Down Expand Up @@ -264,8 +269,6 @@ def process_data(self, data) -> str:
except (AttributeError, TypeError, KeyError) as err:
_LOGGER.debug("No callback configured for evl command.")

_LOGGER.debug('----------------------------------------')

# Return any unprocessed data (uncomplete command)
if not data or len(data) == 0:
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ def parseHandler(self, rawInput):
"""When the envisalink contacts us- parse out which command and data."""
cmd = {}

rawInput = re.sub("[\r\n]", "", rawInput)

if not self._loggedin:
# assume it is login info
code = rawInput
# assume it is login info but look for a sentinel first in case there is other info here
m = re.match(r'[^\r\n%\^]+', rawInput)
if m is None:
# Don't have the full login response yet
return (None, None)
code = m.group(0)
rawInput = rawInput[m.end(0):]
cmd['code'] = code
cmd['data'] = ''
rawInput = None
else:
rawInput = re.sub("[\r\n]", "", rawInput)

# Look for a sentinel
m = re.match("[%\^]", rawInput)
if m is None:
Expand Down

0 comments on commit 8c8b54f

Please sign in to comment.