Skip to content

Commit

Permalink
update zeroDiv handling on filter check, add clustered error handling…
Browse files Browse the repository at this point in the history
… in requests class
  • Loading branch information
BeamCtrl committed Feb 23, 2024
1 parent 4028577 commit 834e877
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
9 changes: 6 additions & 3 deletions airiana-core.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def __init__(self, request_object):
self.elec_now = 0
self.showerRH = None
self.initial_temp = None
self.fanspeed = 1
self.fanspeed = -1
self.system_types = {0: "VR400", 1: "VR700", 2: "VR700DK", 3: "VR400DE", 4: "VTC300", 5: "VTC700",
12: "VTR150K", 13: "VTR200B", 14: "VSR300", 15: "VSR500", 16: "VSR150",
17: "VTR300", 18: "VTR500", 19: "VSR300DE", 20: "VTC200", 21: "VTC100"}
Expand Down Expand Up @@ -709,7 +709,7 @@ def get_filter_status(self):
self.filter = self.req.response
try:
self.filter_remaining = round(100 * (1 - (float(self.filter) / self.filter_limit)), 1)
except ValueError:
except (ValueError, ZeroDivisionError):
traceback.print_exc(ferr)

if self.filter_remaining < 0:
Expand All @@ -723,7 +723,10 @@ def get_filter_status(self):
highend = self.req.response << 16
self.filter_raw = lowend + highend
self.filter = self.filter_limit - (lowend + highend) / (3600 * 24)
self.filter_remaining = round(100 * (1 - (float(self.filter) / self.filter_limit)), 1)
try:
self.filter_remaining = round(100 * (1 - (float(self.filter) / self.filter_limit)), 1)
except ZeroDivisionError:
traceback.print_exc(ferr)
if self.filter_remaining < 0:
self.filter_remaining = 0

Expand Down
26 changes: 7 additions & 19 deletions request.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ def comm_test(self):
second = self.response
print("Testing savecair address 12543:" + str(second) + ";")
os.write(fd, bytes("Testing savecair address 12543:" + str(second) + "\n", "utf-8"))
if (first == 0 and second == 0) \
or (first == "no data" and second == "no data") \
or (first == '' and second == ''):
if ((first == 0 and second == 0)
or (first == "no data" and second == "no data")
or (first == '' and second == '')
or (first == 0 and second == 'no data')
or (first == "no data" and second == 0)):
os.write(fd, bytes("Request object Failed communications test.\n", "utf-8"))
os.close(fd)
return False
Expand Down Expand Up @@ -178,22 +180,14 @@ def modbusregister(self, address, decimals):
self.response = self.client.read_register(
address, decimals,
signed=True)
except IOError:
except (IOError, ValueError, TypeError):
self.connect_errors += 1
if self.connect_errors > 100:
self.error_review()
self.buff += os.read(self.bus, 20) # bus purge
if address == 12543 and self.connect_errors >= 10:
return 0
self.modbusregister(address, decimals)
except ValueError:
self.buff += os.read(self.bus, 20) # bus purge
self.checksum_errors += 1
if address == 12543 and self.checksum_errors >= 10:
return 0
self.modbusregister(address, decimals)
# self.client.precalculate_read_size = False
# print "request om address ", address, "returned", self.response
else:
data = "noData"
try:
Expand All @@ -214,13 +208,7 @@ def write_register(self, reg, value, tries=10):
try:
if tries > 0:
self.client.write_register(reg, value, 0, 6)
except IOError:

self.write_errors += 1
if tries > 0:
self.write_register(reg, value, tries=tries - 1)

except ValueError:
except (IOError, ValueError):
self.write_errors += 1
if tries > 0:
self.write_register(reg, value, tries=tries - 1)
Expand Down

0 comments on commit 834e877

Please sign in to comment.