-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZones.py
executable file
·87 lines (72 loc) · 2.39 KB
/
Zones.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from Zone import Zone
import ConfigParser
import time
from multiprocessing.connection import Client
from GardenPi import GardenPi
###########################################################
# Zones Class
# 2013/2014
# Class for Zones management:
# contain a list zones and manager
# read and weite of configuration file
###########################################################
class Zones:
cfgFileName=""
zones=[]
cfg = GardenPi()
def __init__(self):
#get from parameters the name of the text file for the zone
self.cfgFileName=self.cfg.zoneCfgFile
self.zones=[]
return
def loadValues(self):
self.zones=[]
config=ConfigParser.RawConfigParser()
config.read(self.cfgFileName)
for section in config.sections():
zone = Zone()
zone.zoneid=config.get(section,"zoneid")
zone.name=config.get(section,"name")
zone.description=config.get(section,"description")
zone.imagearea=config.get(section,"imagearea")
zone.days=config.get(section,"days")
zone.start=config.get(section,"start")
zone.duration=config.get(section,"duration")
#zone.started=config.get(section,"zoneid")
#fields = zone.getDefaultFields()
#for value in fields:
# exec (("zone.%s=config.get(section,name)") ,value)
self.zones.append(zone)
return
def saveConfig2(zones):
config=ConfigParser.RawConfigParser()
i=0
while i < len(zones):
section="Zona %u" % (i+1)
config.add_section(section )
for key in zones[i]:
config.set(section,key,zones[i].get(key))
i=i+1
with open(cfgFileName,'wb') as configfile:
config.write(self.configfile)
return
# Start multiple zones, duration has to be float, zones should be a list
def startMultiple(self,duration,zones):
returnZone=[]
for item in zones:
zone = self.zones[int(item)-1]
result = zone.startZone(duration)
time.sleep(duration*60)
return returnZone
# Return a list of zones description
def getAllValuesByName(self,field):
returnZone=[]
for zone in self.zones:
returnZone.append(getattrib(zone,field))
return returnZone
def count(self):
return len(self.zones)
def getZones(self):
return self.zones
def getZoneByID(self,index):
return self.zones[index]