From c5d9b364dac6e6ceddd6510f3eaf7ad1d3a6260f Mon Sep 17 00:00:00 2001 From: Andrew Sayre Date: Wed, 24 Apr 2019 20:25:31 -0500 Subject: [PATCH] Fix heartbeat timeout handling --- pyheos/connection.py | 8 ++++---- pyheos/const.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pyheos/connection.py b/pyheos/connection.py index e9d2424..c414192 100644 --- a/pyheos/connection.py +++ b/pyheos/connection.py @@ -224,7 +224,8 @@ async def _heart_beat(self): if last_activity > threshold: try: await self.commands.heart_beat() - except (ConnectionError, asyncio.IncompleteReadError): + except (ConnectionError, asyncio.IncompleteReadError, + asyncio.TimeoutError): pass await asyncio.sleep(self._heart_beat_interval / 2) @@ -247,10 +248,9 @@ async def command( pending_commands = self._pending_commands[command_name] pending_commands.append(event) # Send command - self._writer.write((uri + SEPARATOR).encode()) - await self._writer.drain() - try: + self._writer.write((uri + SEPARATOR).encode()) + await self._writer.drain() response = await asyncio.wait_for(event.wait(), self.timeout) except (ConnectionError, asyncio.TimeoutError) as error: # Occurs when the connection breaks diff --git a/pyheos/const.py b/pyheos/const.py index 36c3959..dcf8c7b 100644 --- a/pyheos/const.py +++ b/pyheos/const.py @@ -1,12 +1,12 @@ """Define consts for the pyheos package.""" __title__ = "pyheos" -__version__ = "0.4.0" +__version__ = "0.4.1" CLI_PORT = 1255 DEFAULT_TIMEOUT = 10.0 DEFAULT_RECONNECT_DELAY = 10.0 -DEFAULT_HEART_BEAT = 60.0 +DEFAULT_HEART_BEAT = 10.0 DEFAULT_STEP = 5 STATE_CONNECTED = "connected"