-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigDisplay.py
More file actions
145 lines (121 loc) · 4.05 KB
/
ConfigDisplay.py
File metadata and controls
145 lines (121 loc) · 4.05 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
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
#!/usr/bin/python3
# rpi_dashboard
# =================
# Display Configurator
import sys
if sys.version_info[0] < 3:
raise Exception("Python 3 or a more recent version is required.")
# IMPORTS
from disp.conf import disp_conf
from util.helper_coding import helper_coding
# GLOBAL VARIABLES
CONFIG_FILENAME = 'conf/display.json'
# Sub Main for Config
DISP_CONFIG = disp_conf(CONFIG_FILENAME).loadConfig()
def doValueBool(section, key, prompt):
global DISP_CONFIG
if key is None:
if not section in DISP_CONFIG:
DISP_CONFIG[section] = ''
existingValue = DISP_CONFIG[section]
else:
if not section in DISP_CONFIG:
DISP_CONFIG[section] = {}
if not key in DISP_CONFIG[section]:
DISP_CONFIG[section][key] = None
existingValue = DISP_CONFIG[section][key]
newvalue = bool(input(prompt+' ['+str(existingValue)+'] ? ') or existingValue) or None
if key is None:
DISP_CONFIG[section] = newvalue
else:
DISP_CONFIG[section][key] = newvalue
def doValueInt(section, key, prompt):
global DISP_CONFIG
if key is None:
if not section in DISP_CONFIG:
DISP_CONFIG[section] = ''
existingValue = DISP_CONFIG[section]
else:
if not section in DISP_CONFIG:
DISP_CONFIG[section] = {}
if not key in DISP_CONFIG[section]:
DISP_CONFIG[section][key] = None
existingValue = DISP_CONFIG[section][key]
newvalue = int(input(prompt+' ['+str(existingValue)+'] ? ') or existingValue) or None
if key is None:
DISP_CONFIG[section] = newvalue
else:
DISP_CONFIG[section][key] = newvalue
def doValueStr(section, key, prompt):
global DISP_CONFIG
if key is None:
if not section in DISP_CONFIG:
DISP_CONFIG[section] = ''
existingValue = DISP_CONFIG[section]
else:
if not section in DISP_CONFIG:
DISP_CONFIG[section] = {}
if not key in DISP_CONFIG[section]:
DISP_CONFIG[section][key] = None
existingValue = DISP_CONFIG[section][key]
# Process Input
existingValueDisp = existingValue if existingValue is not None else ''
newvalue = input(prompt+' ['+existingValueDisp+'] ? ') or existingValue
if key is None:
DISP_CONFIG[section] = newvalue
else:
DISP_CONFIG[section][key] = newvalue
def doValuePwd(section, key, prompt):
global DISP_CONFIG
if key is None:
if not section in DISP_CONFIG:
DISP_CONFIG[section] = ''
existingValue = DISP_CONFIG[section]
else:
if not section in DISP_CONFIG:
DISP_CONFIG[section] = {}
if not key in DISP_CONFIG[section]:
DISP_CONFIG[section][key] = None
existingValue = DISP_CONFIG[section][key]
try:
decryptedpassword = helper_coding().decode(existingValue)
except Exception as ex:
print("- Unable to read encrypted value")
decryptedpassword = ""
# Process Input
newvalue = input(prompt+' [########] ? ') or decryptedpassword
newvalueencode = helper_coding().encode(newvalue)
if key is None:
DISP_CONFIG[section] = newvalueencode
else:
DISP_CONFIG[section][key] = newvalueencode
print('Raspberry PI Dash Display Setup')
print('from https://github.com/topcats/rpi_dashboard')
print()
print('Setup config (y) ?')
nulyi = input('')
if nulyi == '' or nulyi == 'y':
#all ok
print('')
else:
quit()
#Set Weather Stuff
print('Weather:')
doValueInt('weather', None, 'Town ID')
#Set Location Site Stuff
print('Location:')
doValueInt('location', None, 'Site ID')
#Z-Wave
print('Z-Wave')
doValueBool('zwave', 'enabled', 'Z-Wave Control Enabled (0 will disable)')
doValueStr('zwave', 'url', 'Automation API Base URL Address')
doValueStr('zwave', 'username', 'Username')
doValuePwd('zwave', 'password', 'Password')
doValueStr('zwave', 'tag', 'Device Tag')
#Save it
print()
print('New Config')
nulyi = input('All Ok (Enter y to save) ?')
if nulyi == 'y':
disp_conf(CONFIG_FILENAME).saveConfig(DISP_CONFIG)
print('Saved')