Skip to content

Commit

Permalink
Adding P026 error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
enesbcs committed Mar 7, 2021
1 parent eae4618 commit 634394e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 50 deletions.
101 changes: 65 additions & 36 deletions _P026_Sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
30 changes: 17 additions & 13 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rpieGlobals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down

0 comments on commit 634394e

Please sign in to comment.