-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
95 lines (75 loc) · 2.54 KB
/
config.py
File metadata and controls
95 lines (75 loc) · 2.54 KB
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
88
89
90
91
92
93
94
95
#!/usr/bin/env python
import os, time
import ConfigParser
import logging
logger = logging.getLogger(__name__)
import shiftpi
#local libs
from sensorData import sensorData
#main code
dataPrefix = ""
sensors = {}
configFile = '/home/jasper/Digit/settings.ini'
sched = {}
def readConfig():
now = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime())
logger.info('reading configuration from {0}'.format(configFile, now))
config = ConfigParser.RawConfigParser()
config.read(configFile)
sections = config.sections()
global dataPrefix
dataPrefix = config.get('setup',"dataPrefix")
global relayTest
relayTest = config.getboolean('setup',"relayTest")
global temp_unit
temp_unit = config.get('setup',"temp_unit")
global hum_unit
hum_unit = config.get('setup',"hum_unit")
#read shift pins
SER_PIN = config.getint('setup',"SER_PIN")
RCLK_PIN = config.getint('setup',"RCLK_PIN")
SRCLK_PIN = config.getint('setup',"SRCLK_PIN")
shiftpi.pinsSetup(ser = SER_PIN, rclk = RCLK_PIN, srclk = SRCLK_PIN)
global sensors
for section in sorted(config.sections()):
if section.find('sensor') != -1:
functions = config.get(section,"sensorFunctions").split(',')
setPoint = False
settings = [section,
config.get(section,"name"),
config.get(section,"sensorID"),
config.get(section,"sensorType"),
config.get(section,"sensorFunctions").split(','),
config.get(section,"color"),
config.get(section,"color2"),
config.get(section,"interval")]
if "temp" in functions:
settings.append({'temp':0})
settings.append({'temp_unit':temp_unit})
try:
config.get(section,'temp_relays')
settings.append({'temp_relays':config.get(section,"temp_relays").split(',')})
settings.append({'temp_set':config.get(section,"temp_set")})
settings.append({'temp_setPoint':True})
except:
settings.append({'temp_setPoint':False})
pass
if "hum" in functions:
settings.append({'hum':0})
settings.append({'hum_unit':hum_unit})
try:
config.get(section,'hum_relays')
settings.append({'hum_relays':config.get(section,"hum_relays").split(',')})
settings.append({'hum_set':config.get(section,"hum_set")})
settings.append({'hum_setPoint':True})
except:
settings.append({'hum_setPoint':False})
pass
sensors[section] = sensorData(*settings)
return sensors
def writeConfig(section, key, value):
config = ConfigParser.RawConfigParser()
config.read(configFile)
config.set(section, key, value)
with open(configFile, 'wb') as configfile:
config.write(configfile)