From 634394e9ce210c0bb449c48f4633366cfc421cf9 Mon Sep 17 00:00:00 2001 From: enesbcs Date: Sun, 7 Mar 2021 14:55:20 +0100 Subject: [PATCH] Adding P026 error checks --- _P026_Sysinfo.py | 101 ++++++++++++++++++++++++++++++----------------- commands.py | 30 ++++++++------ rpieGlobals.py | 2 +- 3 files changed, 83 insertions(+), 50 deletions(-) diff --git a/_P026_Sysinfo.py b/_P026_Sysinfo.py index abae360..634116c 100644 --- a/_P026_Sysinfo.py +++ b/_P026_Sysinfo.py @@ -31,50 +31,79 @@ def __init__(self,taskindex): # general init self.timeroptional = False self.formulaoption = True + def plugin_init(self,enableplugin=None): + plugin.PluginProto.plugin_init(self,enableplugin) + self.initialized = True + self.readinprogress = 0 + def webform_load(self): # create html page for settings - choice1 = self.taskdevicepluginconfig[0] - choice2 = self.taskdevicepluginconfig[1] - choice3 = self.taskdevicepluginconfig[2] - choice4 = self.taskdevicepluginconfig[3] - options = ["None","Uptime","Free RAM", "Wifi RSSI","System load","CPU Temp"] - optionvalues = [0,1,2,3,4,5] - webserver.addFormSelector("Indicator1","plugin_026_ind0",6,options,optionvalues,None,choice1) - webserver.addFormSelector("Indicator2","plugin_026_ind1",6,options,optionvalues,None,choice2) - webserver.addFormSelector("Indicator3","plugin_026_ind2",6,options,optionvalues,None,choice3) - webserver.addFormSelector("Indicator4","plugin_026_ind3",6,options,optionvalues,None,choice4) + try: + choice1 = int(self.taskdevicepluginconfig[0]) + except: + choice1 = 0 + try: + choice2 = int(self.taskdevicepluginconfig[1]) + except: + choice2 = 0 + try: + choice3 = int(self.taskdevicepluginconfig[2]) + except: + choice3 = 0 + try: + choice4 = int(self.taskdevicepluginconfig[3]) + except: + choice4 = 0 + try: + options = ["None","Uptime","Free RAM", "Wifi RSSI","System load","CPU Temp"] + optionvalues = [0,1,2,3,4,5] + webserver.addFormSelector("Indicator1","plugin_026_ind0",len(options),options,optionvalues,None,choice1) + webserver.addFormSelector("Indicator2","plugin_026_ind1",len(options),options,optionvalues,None,choice2) + webserver.addFormSelector("Indicator3","plugin_026_ind2",len(options),options,optionvalues,None,choice3) + webserver.addFormSelector("Indicator4","plugin_026_ind3",len(options),options,optionvalues,None,choice4) + except Exception as e: + misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"P026 load "+str(e)) return True def webform_save(self,params): # process settings post reply - for v in range(0,4): - par = webserver.arg("plugin_026_ind"+str(v),params) - if par == "": - par = 0 - if str(self.taskdevicepluginconfig[v])!=str(par): - self.uservar[v] = 0 - self.taskdevicepluginconfig[v] = int(par) - if int(par)>0: - self.valuecount = (v+1) - if self.valuecount == 1: - self.vtype = rpieGlobals.SENSOR_TYPE_SINGLE - elif self.valuecount == 2: - self.vtype = rpieGlobals.SENSOR_TYPE_DUAL - elif self.valuecount == 3: - self.vtype = rpieGlobals.SENSOR_TYPE_TRIPLE - elif self.valuecount == 4: - self.vtype = rpieGlobals.SENSOR_TYPE_QUAD + try: + for v in range(0,4): + par = webserver.arg("plugin_026_ind"+str(v),params) + if par == "": + par = 0 + if str(self.taskdevicepluginconfig[v])!=str(par): + self.uservar[v] = 0 + self.taskdevicepluginconfig[v] = int(par) + if int(par)>0: + self.valuecount = (v+1) + except Exception as e: + misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"P026 save "+str(e)) + try: + if self.valuecount == 1: + self.vtype = rpieGlobals.SENSOR_TYPE_SINGLE + elif self.valuecount == 2: + self.vtype = rpieGlobals.SENSOR_TYPE_DUAL + elif self.valuecount == 3: + self.vtype = rpieGlobals.SENSOR_TYPE_TRIPLE + elif self.valuecount == 4: + self.vtype = rpieGlobals.SENSOR_TYPE_QUAD + except: + pass return True def plugin_read(self): # deal with data processing at specified time interval result = False - if self.initialized and self.readinprogress==0: + if self.initialized and self.readinprogress==0 and self.enabled: self.readinprogress = 1 - for v in range(0,4): - vtype = int(self.taskdevicepluginconfig[v]) - if vtype != 0: - self.set_value(v+1,self.p026_get_value(vtype),False) - self.plugin_senddata() - self._lastdataservetime = rpieTime.millis() - result = True + try: + for v in range(0,4): + vtype = int(self.taskdevicepluginconfig[v]) + if vtype != 0: + self.set_value(v+1,self.p026_get_value(vtype),False) + self.plugin_senddata() + self._lastdataservetime = rpieTime.millis() + result = True + except: + self.readinprogress = 0 self.readinprogress = 0 return result @@ -92,5 +121,5 @@ def p026_get_value(self,ptype): elif ptype == 5: value = OS.read_cpu_temp() except Exception as e: - misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"P026 "+str(e)) + misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"P026 get "+str(e)) return value diff --git a/commands.py b/commands.py index fb2f467..4fe488f 100644 --- a/commands.py +++ b/commands.py @@ -594,22 +594,26 @@ def splitruletoevents(rulestr): # parse rule string into array of events rulearr = rulestr.splitlines() for line in rulearr: cs = line.find(' //') + if cs>-1: + line = line[:cs] + cs = line.find('// ') if cs>-1: line = line[:cs] linelower = line.strip().lower() - if linelower.startswith("on ") and linelower.endswith(" do"): - rcount += 1 - evfound = True - tstr = line.strip().split(" ") - ename = tstr[1] - elif evfound: - if linelower.startswith("endon"): - evfound = False - GlobalRules.append({"ename":ename,"ecat":decodeeventname(ename), "ecode":evarr,"lastcheck":0,"evalue":-1}) - evarr = [] - ename = "" - else: - evarr.append(line.strip()) + if linelower != "": + if linelower.startswith("on ") and linelower.endswith(" do"): + rcount += 1 + evfound = True + tstr = line.strip().split(" ") + ename = tstr[1] + elif evfound: + if linelower.startswith("endon"): + evfound = False + GlobalRules.append({"ename":ename,"ecat":decodeeventname(ename), "ecode":evarr,"lastcheck":0,"evalue":-1}) + evarr = [] + ename = "" + else: + evarr.append(line.strip()) def getfirstequpos(cstr): res = -1 diff --git a/rpieGlobals.py b/rpieGlobals.py index 4138057..d89255a 100644 --- a/rpieGlobals.py +++ b/rpieGlobals.py @@ -6,7 +6,7 @@ # Copyright (C) 2018-2020 by Alexander Nagy - https://bitekmindenhol.blog.hu/ # PROGNAME = "RPIEasy" -BUILD = 21065 +BUILD = 21066 PROGVER = str(BUILD)[:1]+"."+str(BUILD)[1:2]+"."+str(BUILD)[2:] gpMenu = []