Skip to content

Commit

Permalink
Fixing capital eventname handling, global variable resolving in rules…
Browse files Browse the repository at this point in the history
…, duplicated taskname denial, P026 extra checks
  • Loading branch information
enesbcs committed Mar 6, 2021
1 parent eb09739 commit eae4618
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 19 deletions.
2 changes: 1 addition & 1 deletion _P019_PCF8574.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def plugin_write(self,cmd): # handle incoming commands
pin = -1
trpin = -1
if pin>-1 and val in [0,1] and trpin >-1:
misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"PCFPIO"+str(pin)+" set to "+str(val))
misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"PCFGPIO"+str(pin)+" set to "+str(val))
try:
tmcp = lib_pcfrouter.request_pcf_device(int(pin))
tmcp.writepin(trpin, val)
Expand Down
23 changes: 13 additions & 10 deletions _P026_Sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ def plugin_read(self): # deal with data processing at specified time interval

def p026_get_value(self,ptype):
value = 0
if ptype == 1:
value = rpieTime.getuptime(0)
elif ptype == 2:
value = OS.FreeMem()
elif ptype == 3:
value = OS.get_rssi()
elif ptype == 4:
value = OS.read_cpu_usage()
elif ptype == 5:
value = OS.read_cpu_temp()
try:
if ptype == 1:
value = rpieTime.getuptime(0)
elif ptype == 2:
value = OS.FreeMem()
elif ptype == 3:
value = OS.get_rssi()
elif ptype == 4:
value = OS.read_cpu_usage()
elif ptype == 5:
value = OS.read_cpu_temp()
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"P026 "+str(e))
return value
5 changes: 3 additions & 2 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def doExecuteCommand(cmdline,Parse=True):
c2 = retval.split(" ")
cmdarr = retval[(fsp+1):].split(",")
cmdarr = [c2[0]] + cmdarr
oldcmd = cmdarr[0]
cmdarr[0] = cmdarr[0].strip().lower()
commandfound = False
misc.addLog(rpieGlobals.LOG_LEVEL_INFO,"CMD: "+cmdline.replace("==","="))
Expand Down Expand Up @@ -213,7 +214,7 @@ def doExecuteCommand(cmdline,Parse=True):
return commandfound

elif cmdarr[0] == "event":
cmdargs = cmdline.replace(cmdarr[0],"",1)[1:]
cmdargs = cmdline.replace(oldcmd,"",1)[1:]
cmdargs = cmdargs.replace(",","=",1).strip()
rulesProcessing(cmdargs,rpieGlobals.RULE_USER)
commandfound = True
Expand Down Expand Up @@ -997,7 +998,7 @@ def parseruleline(linestr,rulenum=-1):
else:
state = "INV"
if tval!="None":
cline = cline.replace("["+m[r]+"]",tval)
cline = cline.replace("["+m[r]+"]",str(tval))
else:
print("Please avoid special characters in names! ",linestr)
if ("%eventvalue%" in linestr) and (rulenum!=-1):
Expand Down
5 changes: 4 additions & 1 deletion linux_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ def read_cpu_usage():
except:
cpu_a_cur = 0
cpu_t_cur = 1
cpu_util = misc.str2num2(100*(cpu_a_cur-cpu_a_prev) / (cpu_t_cur-cpu_t_prev))
try:
cpu_util = misc.str2num2(100*(cpu_a_cur-cpu_a_prev) / (cpu_t_cur-cpu_t_prev))
except:
cpu_util = 0
return cpu_util

def get_memory():
Expand Down
12 changes: 12 additions & 0 deletions misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,15 @@ def get_battery_value():
elif bval>100:
bval = 100
return bval

def get_taskname_taskids(taskname):
res = []
for i in range(len(Settings.Tasks)):
try:
if type(Settings.Tasks[i]) is not bool:
if Settings.Tasks[i].taskname.lower() == taskname:
if i not in res:
res.append(i)
except:
pass
return res
4 changes: 2 additions & 2 deletions 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 = 21063
BUILD = 21065
PROGVER = str(BUILD)[:1]+"."+str(BUILD)[1:2]+"."+str(BUILD)[2:]

gpMenu = []
Expand Down Expand Up @@ -49,7 +49,7 @@
CMD_WIFI_DISCONNECT = 135

DEVICES_MAX = 75
TASKS_MAX = 64
TASKS_MAX = 96

CONTROLLER_MAX = 4
NOTIFICATION_MAX = 4
Expand Down
21 changes: 18 additions & 3 deletions webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ def handle_devices(self):
page = setpage
else:
page = int(rpieGlobals.TASKS_MAX / TASKS_PER_PAGE)

taskIndexNotSet = (taskIndex == 0) or (taskIndex == '')
if taskIndex!="":
taskIndex = int(taskIndex) - 1
Expand Down Expand Up @@ -1652,7 +1652,7 @@ def handle_devices(self):
else:
Settings.Tasks[taskIndex].plugin_init() # call plugin init / (arg("TDE",responsearr) == "on")
except:
pass
pass

if edit != '' and not(taskIndexNotSet): # when form submitted
if taskdevicenumber != 0: # save settings
Expand All @@ -1664,7 +1664,22 @@ def handle_devices(self):
else:
Settings.Tasks[taskIndex].interval = 0
tasknamestr = str(arg("TDN",responsearr)).strip()
Settings.Tasks[taskIndex].taskname = tasknamestr.replace(" ","")
Settings.Tasks[taskIndex].taskname = tasknamestr.replace(" ","") #remove space from taskname

try:
import random
tname = Settings.Tasks[taskIndex].taskname
namecheck = True
while namecheck:
idvars = misc.get_taskname_taskids(tname)
if (len(idvars)==1 and (taskIndex not in idvars)) or (len(idvars)>1): #duplicated tasknames denied
tname = Settings.Tasks[taskIndex].taskname + str(int(random.random() * 100))
else:
namecheck = False
Settings.Tasks[taskIndex].taskname = tname
except Exception as e:
print(e)

if tasknamestr:
Settings.Tasks[taskIndex].taskdeviceport = arg("TDP",responsearr)
maxcon = len(Settings.Controllers)
Expand Down

0 comments on commit eae4618

Please sign in to comment.