Пример #1
0
def load_rules():
    #Load rules data from json file into memory."""
    global rdict
    try:
	with open('./data/fcRules.json'):
	    pass
    except IOError:
		data = { "rules": [] }
		ospi.jsave(data, 'fcRules')

    rfile = open('./data/fcRules.json', 'r')
    rdict = json.load(rfile)
    rfile.close()
    return rdict
Пример #2
0
    def GET(self):
		rdict = load_rules()
		qdict = web.input()
		
		#delete all rules
		if str(qdict['rid']) == '-1':
			del rdict['rules'][:]
			ospi.jsave(rdict, 'fcRules')
		#delete selected rule
		else:
			iIndex = 0
			for rule in rdict['rules']:
				if int(rule['rid']) == int(qdict['rid']):
					del rdict['rules'][iIndex]
				iIndex += 1
		ospi.jsave(rdict, 'fcRules')
		raise web.seeother('/vfc')
		return 
Пример #3
0
    def GET(self):
	# Declare global variables
        global rdict
        global RunHour
        global RunMinute

	# load dictionaries
	qdict = web.input()

	# Save new runtime to global variables
	RunHour = qdict['RuntimeHr']
	RunMinute = qdict['RuntimeMin']
	
	# Save query dictionary to fcSettings.json file
	ospi.jsave(qdict, 'fcSettings')

	# re-direct
	raise web.seeother('/vfc')
	return   
Пример #4
0
    def GET(self):
		global rdict
		rdict = load_rules()
		qdict = web.input()
		if str(qdict['enabled']) == 'on':
			qdict['enabled'] = 'true'
		#add new rule
		if str(qdict['rid']) == '-1':
			iRid = 0
			for rule in rdict['rules']:
				if int(rule['rid']) > iRid:
					iRid = int(rule['rid'])
			qdict['rid'] = iRid + 1
			rdict['rules'].append(qdict)
		#replace existing rule
		else:
			iIndex = 0
			for rule in rdict['rules']:
				if int(rule['rid']) == int(qdict['rid']):
					rdict['rules'][iIndex] = qdict
				iIndex += 1
		ospi.jsave(rdict, 'fcRules')
		raise web.seeother('/vfc')
		return   
Пример #5
0
def EditProgram():
    global pdict
    global High
    global Precip
    try:
		pdict = ospi.load_programs() #load program file to memory
		rdict = load_rules() #load rules file to memory
		
		#Loop through each rule, and enable/disable programs as configured
		for rule in rdict['rules']:
			#Enable/Disable programs based on Temperature rules
			if str(rule['type']) == 'Temperature' and rule['enabled'] == 'true':
				if rule['eval'] == '>' and int(High) >= int(rule['thresh']):
					if rule['action'] == 'Enable':
						print('Enable Program ', str(rule['prog']))
						mp = pdict[int(rule['prog'])]
						mp[0] = 1
						pdict[int(rule['prog'])] = mp
						ospi.jsave(pdict, 'programs')
					elif rule['action'] == 'Disable':
						print('Disable Program ', str(rule['prog']))
						mp = pdict[int(rule['prog'])]
						mp[0] = 0
						pdict[int(rule['prog'])] = mp
						ospi.jsave(pdict, 'programs')
				elif rule['eval'] == '<' and int(High) <= int(rule['thresh']):
					if rule['action'] == 'Enable':
						print('Enable Program ', str(rule['prog']))
						mp = pdict[int(rule['prog'])]
						mp[0] = 1
						pdict[int(rule['prog'])] = mp
						ospi.jsave(pdict, 'programs')
					elif rule['action'] == 'Disable':
						print('Disable Program ', str(rule['prog']))
						mp = pdict[int(rule['prog'])]
						mp[0] = 0
						pdict[int(rule['prog'])] = mp
						ospi.jsave(pdict, 'programs')
			#Enable/Disable programs based on Precip rules
			elif str(rule['type']) == 'Precip' and rule['enabled'] == 'true':
				if rule['eval'] == '>' and float(Precip) >= float(rule['thresh']):
					print('Precip > ', str(rule['thresh']))
					if rule['action'] == 'Enable':
						print('Enable Program ', str(rule['prog']))
						mp = pdict[int(rule['prog'])]
						mp[0] = 1
						pdict[int(rule['prog'])] = mp
						ospi.jsave(pdict, 'programs')
					elif rule['action'] == 'Disable':
						print('Disable Program ', str(rule['prog']))
						mp = pdict[int(rule['prog'])]
						mp[0] = 0
						pdict[int(rule['prog'])] = mp
						ospi.jsave(pdict, 'programs')
				if rule['eval'] == '<' and float(Precip) <= float(rule['thresh']):
					if rule['action'] == 'Enable':
						print('Enable Program ', str(rule['prog']))
						mp = pdict[int(rule['prog'])]
						mp[0] = 1
						pdict[int(rule['prog'])] = mp
						ospi.jsave(pdict, 'programs')
					elif rule['action'] == 'Disable':
						print('Disable Program ', str(rule['prog']))
						mp = pdict[int(rule['prog'])]
						mp[0] = 0
						pdict[int(rule['prog'])] = mp
						ospi.jsave(pdict, 'programs')
    except:
		pass