From 1dd092ebe4f993283a6f9d388bf2bd45550454b7 Mon Sep 17 00:00:00 2001 From: Jevgeni Kiski Date: Sat, 18 Apr 2020 00:19:14 +0300 Subject: [PATCH] A better place for last_exception resetting --- nextion/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nextion/client.py b/nextion/client.py index 22a6a99..9c0390a 100644 --- a/nextion/client.py +++ b/nextion/client.py @@ -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] @@ -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) @@ -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 @@ -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):