Skip to content

Commit

Permalink
A better place for last_exception resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
yozik04 committed Apr 17, 2020
1 parent 231de5b commit 1dd092e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions nextion/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .exceptions import CommandFailed, CommandTimeout, ConnectionFailed
from .protocol import EventType, NextionProtocol, ResponseType

IO_TIMEOUT = 0.5 # picture change on background takes 180ms + first variable set after wakeup takes 240ms
IO_TIMEOUT = 0.5 # Background picture change takes 180ms + first variable set after a wakeup takes 240ms + some buffer.
BAUDRATES = [2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400]


Expand Down Expand Up @@ -199,6 +199,7 @@ async def _command(self, command, timeout=IO_TIMEOUT, attempts=None):
try:
logger.info("Reconnecting")
await self.connect()
last_exception = None
except ConnectionFailed:
logger.error("Reconnect failed")
await asyncio.sleep(1)
Expand All @@ -212,7 +213,6 @@ async def _command(self, command, timeout=IO_TIMEOUT, attempts=None):
except asyncio.QueueEmpty:
pass

last_exception = None
self._connection.write(command)

result = None
Expand Down Expand Up @@ -256,7 +256,7 @@ async def _command(self, command, timeout=IO_TIMEOUT, attempts=None):
else: # this will run if loop ended successfully
return data if data is not None else result

if last_exception:
if last_exception is not None:
raise last_exception

async def command(self, command, timeout=IO_TIMEOUT, attempts=None):
Expand Down

0 comments on commit 1dd092e

Please sign in to comment.