From 834e8773d8e4fcea3cea6db31724cb46d66800d7 Mon Sep 17 00:00:00 2001 From: Daniel Halling Date: Fri, 23 Feb 2024 12:48:59 +0100 Subject: [PATCH] update zeroDiv handling on filter check, add clustered error handling in requests class --- airiana-core.py | 9 ++++++--- request.py | 26 +++++++------------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/airiana-core.py b/airiana-core.py index a5b9716..75d9b54 100755 --- a/airiana-core.py +++ b/airiana-core.py @@ -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"} @@ -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: @@ -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 diff --git a/request.py b/request.py index b31da2a..8cef80f 100644 --- a/request.py +++ b/request.py @@ -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 @@ -178,7 +180,7 @@ 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() @@ -186,14 +188,6 @@ def modbusregister(self, address, decimals): 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: @@ -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)