From c39d63c843aa65da26230ec9d6de05ae183b2613 Mon Sep 17 00:00:00 2001 From: Adam Harley Date: Thu, 19 Dec 2019 21:09:59 +0000 Subject: [PATCH] use correct variable for scope in i2c i/o errors The i2c i/o error code currently tried to use `e` which only exists in the scope of the earlier `except` block. The correct scope variable is `error` which `e` is assigned out to. The existing code will yield UnboundLocalError "local variable 'e' referenced before assignment" instead of passing the original error. --- simbamon/mopiapi.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/simbamon/mopiapi.py b/simbamon/mopiapi.py index b1f48c1..cba6850 100644 --- a/simbamon/mopiapi.py +++ b/simbamon/mopiapi.py @@ -113,9 +113,9 @@ def readConfig(self, input=0): tries += 1 # unsucessfully read if error != 0: - if e.errno == errno.EIO: - e.strerror = "I2C bus input/output error on read config" - raise e + if error.errno == errno.EIO: + error.strerror = "I2C bus input/output error on read config" + raise error if tries == MAXTRIES or (self.maj == 3 and self.minr > 9 and data[0] == 255): raise IOError(errno.ECOMM, "Communications protocol error on read config") # behaivour changed at v3.10 to 5x0 so that 255 could serve as error detection @@ -169,9 +169,9 @@ def writeConfig(self, battery, input=0): tries += 1 # unsucessfully written if error != 0: - if e.errno == errno.EIO: - e.strerror = "I2C bus input/output error on send config" - raise e + if error.errno == errno.EIO: + error.strerror = "I2C bus input/output error on send config" + raise error if tries == MAXTRIES: raise IOError(errno.ECOMM, "Communications protocol error on send config") @@ -208,9 +208,9 @@ def baseReadWord(self, register): tries += 1 # unsucessfully read if error != 0: - if e.errno == errno.EIO: - e.strerror = "I2C bus input/output error on read word" - raise e + if error.errno == errno.EIO: + error.strerror = "I2C bus input/output error on read word" + raise error if data == 0xFFFF: raise IOError(errno.ECOMM, "Communications protocol error on read word") return data @@ -260,9 +260,9 @@ def writeWord(self, register, data): tries += 1 # unsucessfully written if error != 0: - if e.errno == errno.EIO: - e.strerror = "I2C bus input/output error on write word" - raise e + if error.errno == errno.EIO: + error.strerror = "I2C bus input/output error on write word" + raise error if tries == MAXTRIES: raise IOError(errno.ECOMM, "Communications protocol error on write word")