-
-
Notifications
You must be signed in to change notification settings - Fork 156
/
gv.py
316 lines (298 loc) · 8.51 KB
/
gv.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/usr/bin/python
# -*- coding: utf-8 -*-
# standard library imports
from calendar import timegm
from collections import OrderedDict
import json
import os
import subprocess
from threading import RLock
import time
##############################
#### Revision information ####
major_ver = 5
minor_ver = 1
revision = 999
old_count = 1137 # update this to reset revision number.
try:
revision = int(subprocess.check_output(["git", "rev-list", "--count", "HEAD"]))
ver_str = f"{major_ver}.{minor_ver}.{revision - old_count}"
except Exception:
print("adding git safe.directory exception")
sip_dir = os.getcwd()
command = f"git config --global --add safe.directory {sip_dir}"
subprocess.call(command.split())
revision = int(subprocess.check_output(["git", "rev-list", "--count", "HEAD"]))
ver_str = f"{major_ver}.{minor_ver}.{revision - old_count}"
try:
ver_date = subprocess.check_output(
["git", "log", "-1", "--format=%cd", "--date=short"]
).strip()
ver_date = ver_date.decode('utf-8')
except Exception as e:
print(_("Could not use git to determine version and date of last commit!"), e)
ver_date = "2015-01-09"
#####################
#### Global vars ####
# Settings Dictionary. A set of vars kept in memory and persisted in a file.
# Edit this default dictionary definition to add or remove "key": "value" pairs or change defaults.
# note old passphrases stored in the "pwd" option will be lost - reverts to default passphrase.
sd = {
"en": 1,
"seq": 1,
"ir": [0],
"iw": [0],
"rsn": 0,
"htp": 80,
"htip": "::",
"nst": 8,
"rdst": 0,
"loc": "",
"tz": 48,
"tf": 1,
"rs": 0,
"rd": 0,
"mton": 0,
"lr": 100,
"sdt": 0,
"mas": 0,
"wl": 100,
"bsy": 0,
"lg": 1,
"urs": 0,
"nopts": 13,
"upas": 0,
"rst": 1,
"mm": 0,
"mo": [0],
"rbt": 0,
"mtoff": 0,
"nbrd": 1,
"tu": "C",
"snlen": 32,
"name": "SIP",
"theme": "basic",
"show": [255],
"passphrase": "12d4e6fc471fbe073df5a0678fcffb9f75b12161e4e3f6d1e1bd81ffb22163bf",
"lang": "default",
"idd": 0,
"pigpio": 0,
"alr": 0
}
try:
with open("./data/sd.json", "r") as sdf: # A config file
sd_temp = json.load(sdf)
for key in sd: # If file loaded, replce default values in sd with values from file
if key in sd_temp:
sd[key] = sd_temp[key]
except IOError: # If file does not exist, it will be created using defaults.
with open("./data/sd.json", "w") as sdf: # save file
json.dump(sd, sdf, indent=4, sort_keys=True)
if sd["pigpio"]:
try:
subprocess.check_output("pigpiod", stderr=subprocess.STDOUT)
use_pigpio = True
except Exception as e:
use_pigpio = False
print(_("pigpio not found. Using RPi.GPIO"), e)
else:
use_pigpio = False
from helpers import load_programs, station_names, days_since_epoch
rn = 0
day_ord = 0
node_runs = {}
now = time.time()
nowt = time.localtime(now)
dse = days_since_epoch()
tz_offset = round(now - timegm(nowt)
) # compatible with Javascript (negative tz shown as positive value)
plugin_menu = [] # Empty list of lists for plugin links (e.g. ["name", "URL"])
srvals = [0] * (sd["nst"]) # Shift Register values
output_srvals = [0] * (sd["nst"]) # Shift Register values last set by set_output()
output_srvals_lock = RLock()
rovals = [0] * sd["nbrd"] * 7 # Run Once durations
snames = station_names() # Load station names from file
pnames = [] # do this before load_programs so it can be populated
pd = load_programs() # Load program data from file
plugin_data = {} # Empty dictionary to hold plugin based global data
pluginFtr = [] # Empty list to hold plugin data for display in footer
pluginStn = [] # Empty list to hold plugin data for display on timeline
plugin_scripts = [] # Empty list of script file names for script injections requested by plugins
plugin_adj = 0 # holds wl adjustment set by plugins
ps = [] # Program schedule (used for UI display)
for i in range(sd["nst"]):
ps.append([0, 0])
bsy = 0 # A program is running
pon = None # Program on (Holds program number of a running program)
sbits = [0] * (sd["nbrd"] + 1) # Used to display stations that are on in UI
prd = 2 # page refresh delay
rs = [] # run schedule
for j in range(sd["nst"]):
rs.append(
[0, 0, 0, 0]
) # scheduled start time, scheduled stop time, duration, program index
lrun = [0, 0, 0, 0] # station index, program number, duration, end time (Used in UI)
scount = (
0
) # Station count, used in set station to track on stations with master association.
use_gpio_pins = True
options = [
[
_("System name"),
"string",
"name",
_("Unique name of this SIP system."),
_("System"),
],
[
_("Location"),
"string",
"loc",
_("City name or zip code. Use comma or + in place of space."),
_("System"),
],
[_("Language"), "list", "lang", _("Select language."), _("System")],
[
_("24-hour clock"),
"boolean",
"tf",
_("Display times in 24 hour format (as opposed to AM/PM style.)"),
_("System"),
],
[_("HTTP port"), "int", "htp", _("HTTP port."), _("System")],
[
_("HTTP IP addr"),
"string",
"htip",
_("IP Address used for HTTP server socket. IPv4 or IPv6 address"),
_("System"),
],
[
_("Use pigpio"),
"boolean",
"pigpio",
_("GPIO Library to use. Default is RPi.GPIO"),
_("System"),
],
[
_("Water Scaling"),
"int",
"wl",
_("Water scaling (as %), between 0 and 100."),
_("System"),
],
[
_("Station Names"),
"external",
"stations",
_("Define your own station names and options: Which stations are connected/enabled? Which one (if any) controls the master valve? Should a station ignore adjustmenst from rain or plugins? Should a station require the master valve to be activated to run?"),
_("Stations"),
],
[
_("Sequential"),
"boolean",
"seq",
_("Sequential or concurrent running mode."),
_("Station Handling"),
],
[
_("Individual Duration"),
"boolean",
"idd",
_("Allow each station to have its own run time in programs."),
_("Station Handling"),
],
[
_("Station extensions"),
"int",
"nbrd",
_("Add 8 stations for each extension."),
_("Station Handling"),
],
[
_("Station delay"),
"int",
"sdt",
_("Station delay time (in seconds), between 0 and 240."),
_("Station Handling"),
],
[
_("Active-Low Relay"),
"boolean",
"alr",
_("Using active-low relay boards connected through shift registers"),
_("Station Handling"),
],
[
_("Master on delay"),
"int",
"mton",
_("Master on delay (in seconds), between -60 and +60."),
_("Station Handling"),
],
[
_("Master off delay"),
"int",
"mtoff",
_("Master off delay (in seconds), between -60 and +60."),
_("Station Handling"),
],
[
_("Use rain sensor"),
"boolean",
"urs",
_("Use rain sensor."),
_("Rain Sensor"),
],
[
_("Normally open"),
"boolean",
"rst",
_("Rain sensor type."),
_("Rain Sensor"),
],
[
_("Enable logging"),
"boolean",
"lg",
_(
"Log all events - note that repetitive writing to an SD card can shorten its lifespan."
),
_("Logging"),
],
[
_("Max log entries"),
"int",
"lr",
_("Length of log to keep, 0=no limits."),
_("Logging"),
],
[
_("Enable passphrase"),
"boolean",
"upas",
_("Minimal security. \nPrevent unauthorized users from accessing the system without a passphrase. \n*** Default is opendoor ***"),
_("Manage Passphrase"),
],
[
_("Current passphrase"),
"password",
"opw",
_("Enter the current passphrase. \n*** Defalut is opendoor ***"),
_("Manage Passphrase"),
],
[
_("New passphrase"),
"password",
"npw",
_("Enter a new passphrase."),
_("Manage Passphrase"),
],
[
_("Confirm passphrase"),
"password",
"cpw",
_("Confirm the new passphrase."),
_("Manage Passphrase"),
],
]