forked from oepi-loepi/toonWater
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWaterConfigScreen.qml
More file actions
641 lines (570 loc) · 15.9 KB
/
Copy pathWaterConfigScreen.qml
File metadata and controls
641 lines (570 loc) · 15.9 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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
import QtQuick 2.1
import BasicUIControls 1.0
import qb.components 1.0
import FileIO 1.0
Screen {
id: waterConfigScreen
screenTitle: "Water"
property int configChangeStep : 0
property bool stepRunning : false
property bool needReboot : false
property bool needRestart : false
property string tempEspURL: app.urlEspString
property string tempDomURL: app.urlDomString
property string tempdomIdxFlow: app.domIdxFlow
property string tempdomIdxQuantity: app.domIdxQuantity
property bool tempDomMode: app.domMode
property bool updateAvailable: app.updateAvailable
property string fieldText1 : "Nieuwe waterstand:"
property string tempTotal: app.waterquantity
property bool waterTotalChanged : false
property bool waterTarifffound: false
property string oldConfigQmfFileString
property bool debugOutput : app.debugOutput
FileIO {id: qmf_tenant_Configfile; source: "file:///qmf/etc/qmf_tenant.xml"}
FileIO {id: qmf_tenant_Configfile_bak; source: "file:///qmf/etc/qmf_tenant.waterbackup"}
FileIO {id: pwrusageFile; source: "file:///mnt/data/qmf/config/config_happ_pwrusage.xml"}
FileIO {id: pwrusageFileBak; source: "file:///mnt/data/qmf/config/config_happ_pwrusage.bak"}
FileIO {id: usageInfo; source: "usageInfo.txt"}
FileIO {id: billingInfo; source: "billingInfo.txt"}
onShown: {
addCustomTopRightButton("Opslaan")
getTariff()
enableDomMode.isSwitchedOn = tempDomMode
inputField1.inputText = tempTotal
espIP.inputText =tempEspURL
domoticzIP.inputText = tempDomURL
idxFlow.inputText = tempdomIdxFlow
idxQuantity.inputText = tempdomIdxQuantity
}
onCustomButtonClicked: {
configChangeStep = 0
stepRunning = true
}
function saveFieldData1(text) {
tempTotal= text
if (tempTotal != app.waterquantity){waterTotalChanged = true}
}
function saveespURL(text) {
if (text) {
tempEspURL = text;
}
}
function saveDomoticzURL1(text) {
if (text) {
tempDomURL = text;
}
}
function saveidxFlow(text) {
if (text) {
tempdomIdxFlow = text;
}
}
function saveidxQuantity(text) {
if (text) {
tempdomIdxQuantity = text;
}
}
Text {
id: mytext1
text: "Instellingen"
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 18:14
anchors {
top: parent.top
left: parent.left
leftMargin: 20
topMargin:20
}
}
EditTextLabel4421 {
id: inputField1
width: (parent.width*0.4) - 40
height: 30
leftTextAvailableWidth: 200
leftText: "Handmatig totaal (geen kommas, punten spaties etc"
labelFontSize: isNxt ? 18:14
labelFontFamily: qfont.semiBold.name
anchors {
left: idxQuantity.left
top: mytext1.bottom
topMargin: 6
}
onClicked: {
qkeyboard.open(inputField1.leftText, inputField1.inputText, saveFieldData1)
}
}
NewTextLabel {
id: tariffButton
width: isNxt ? 284 : 220
height: isNxt ? 35 : 30
buttonActiveColor: "lightgrey"
buttonHoverColor: "blue"
enabled : true
textColor : "black"
textDisabledColor : "grey"
buttonText: "tarieven"
anchors {
top: mytext1.bottom
topMargin: 6
left: inputField1.right
leftMargin: 30
}
onClicked: {
onClicked: {stage.openFullscreen(app.waterTariffScreenUrl)}
}
visible: waterTarifffound
}
NewTextLabel {
id: savequantityText
width: isNxt ? 120 : 96;
height: isNxt ? 40:32
buttonActiveColor: "lightgreen"
buttonHoverColor: "blue"
enabled : true
textColor : "black"
buttonText: "Annuleer"
anchors {
top: inputField1.top
left: inputField1.right
leftMargin: isNxt? 20: 16
}
onClicked: {
tempTotal = app.waterquantity
inputField1.inputText = tempTotal
waterTotalChanged = false
}
visible: waterTotalChanged
}
Text {
id: warning1TXT
width: parent.width
text: "Deze versie ondersteund het uitlezen van Domoticz in plaats van een ESP (Wemos)"
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 18:14
anchors {
left: parent.left
leftMargin: isNxt ? 20:16
top:savequantityText.bottom
topMargin: isNxt ? 10:8
}
}
Text {
id: warning2TXT
width: parent.width
text: "Echter wordt dringend geadviseerd de mogelijkheid van de ESP optie te gebruiken in plaats van de Domoticz optie."
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 18:14
anchors {
left: parent.left
leftMargin: isNxt ? 20:16
top:warning1TXT.bottom
}
}
Text {
id: warning3TXT
width: parent.width
text: "De Domoticz optie is namelijk traag en zal achter lopen op de werkelijkheid."
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 18:14
anchors {
left: parent.left
leftMargin: isNxt ? 20:16
top:warning2TXT.bottom
}
}
Text {
id: domModeTXT
width: 160
text: "Domoticz Mode"
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 18:14
anchors {
left: parent.left
leftMargin: isNxt ? 20:16
top:warning3TXT.bottom
topMargin: isNxt ? 10:8
}
}
OnOffToggle {
id: enableDomMode
height: 30
leftIsSwitchedOn: true
anchors {
left: domModeTXT.right
leftMargin: isNxt ? 60 : 48
top: domModeTXT.top
}
onSelectedChangedByUser: {
if (isSwitchedOn) {
tempDomMode = true;
} else {
tempDomMode = false; }
}
}
Text {
id: domModeTXT2
width: 160
text: "ESP Mode, maakt gebruik van een geflashde Wemos D1 Mini"
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 18:14
anchors {
left: enableDomMode.right
leftMargin: isNxt ? 65 : 25
top: domModeTXT.top
}
}
Text {
id: myLabel
text: "IP adres van de ESP (bijvoorbeeld: 192.168.10.135)"
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 18:14
anchors {
left: parent.left
top: domModeTXT.bottom
leftMargin: 20
topMargin: 10
}
visible: !tempDomMode
}
EditTextLabel4421 {
id: espIP
width: (parent.width*0.6)
height: 30
leftTextAvailableWidth: 200
leftText: "esp8266 IP"
labelFontSize: isNxt ? 18:14
labelFontFamily: qfont.semiBold.name
anchors {
left: myLabel.left
top: myLabel.bottom
topMargin: 10
}
onClicked: {
qkeyboard.open("IP adres van de ESP", espIP.inputText, saveespURL)
}
visible: !tempDomMode
}
Text {
id: updateAvailable1
text: "Update van de ESP beschikbaar, zie domoticaforum voor instructies om deze opnieuw te flashen:"
anchors {
top: espIP.bottom
topMargin: 10
left: myLabel.left
}
font.pixelSize: isNxt ? 18:14
font.family: qfont.bold.name
visible: !tempDomMode & updateAvailable
}
Text {
id: updateAvailable2
text: "https://www.domoticaforum.eu/viewtopic.php?t=13090"
anchors {
top: updateAvailable1.bottom
topMargin: 5
left: myLabel.left
}
font.pixelSize: isNxt ? 18:14
font.family: qfont.bold.name
visible: !tempDomMode & updateAvailable
}
Text {
id: myLabel88
text: "URL van Domoticz (bijvoorbeekd: http://192.168.10.185:8080)"
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 18:14
anchors {
left: parent.left
top: domModeTXT.bottom
leftMargin: 20
topMargin: 10
}
visible: tempDomMode
}
EditTextLabel4421 {
id: domoticzIP
width: (parent.width*0.6)
height: 30
leftTextAvailableWidth: 200
leftText: "Domoticz URL"
labelFontSize: isNxt ? 18:14
labelFontFamily: qfont.semiBold.name
anchors {
left: myLabel.left
top: myLabel.bottom
topMargin: 10
}
onClicked: {
qkeyboard.open("URL van Domoticz incl. Port", domoticzIP.inputText, saveDomoticzURL1)
}
visible: tempDomMode
}
Text {
id: myLabel2
text: "IDX from Domoticz (Devices Tab) :"
font.pixelSize: isNxt ? 20 : 16
font.family: qfont.regular.name
anchors {
left: myLabel.left
top: domoticzIP.bottom
topMargin: 10
}
visible: tempDomMode
}
EditTextLabel4421 {
id: idxFlow
width: (parent.width*0.4) - 40
height: 30
leftTextAvailableWidth: 200
leftText: "Flow IDX"
labelFontSize: isNxt ? 18:14
labelFontFamily: qfont.semiBold.name
anchors {
left: myLabel2.left
top: myLabel2.bottom
topMargin: 6
}
onClicked: {
qkeyboard.open("Flow IDX", idxFlow.inputText, saveidxFlow)
}
visible: tempDomMode
}
EditTextLabel4421 {
id: idxQuantity
width: (parent.width*0.4) - 40
height: 30
leftTextAvailableWidth: 200
leftText: "Quantity IDX"
labelFontSize: isNxt ? 18:14
labelFontFamily: qfont.semiBold.name
anchors {
left: idxFlow.left
top: idxFlow.bottom
topMargin: 6
}
onClicked: {
qkeyboard.open("Meter IDX", idxQuantity.inputText, saveidxQuantity)
}
visible: tempDomMode
}
Image {
id: qrCode
source: "file:///qmf/qml/apps/toonWater/drawables/qrCode.png"
anchors {
right: parent.right
bottom: parent.bottom
rightMargin:10
bottomMargin:10
}
width: isNxt ? 150:120
height: isNxt ? 150:120
fillMode: Image.PreserveAspectFit
}
Text {
id: myLabel90
text: "Nog geen meter?"
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 18:14
anchors {
horizontalCenter: qrCode.horizontalCenter
bottom: qrCode.top
bottomMargin:10
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getTariff(){
console.log("*********Water check billingInfo in config_happ_pwrusage.xml")
var waterfound = false
var pwrusageString = pwrusageFile.read()
var pwrusageArray = pwrusageString.split("<billingInfo>")
for (var t in pwrusageArray){
var n201 = pwrusageArray[t].indexOf('</billingInfo>')
var partOfString = pwrusageArray[t].substring(0, n201)
if (partOfString.indexOf("water")>-1){
waterTarifffound = true
}
}
}
function modRRDConfig(configChangeStep){
var configfileString
var oldconfigfileString
var oldpwrusageString = pwrusageFile.read()
if (debugOutput) console.log("*********Water configChangeStep = " + configChangeStep)
switch (configChangeStep) {
case 0: {
console.log("*********Water show popup")
app.popupString = "Water instellen en herstarten als nodig" + "..."
app.waterRebootPopup.show()
break;
}
case 1: {
console.log("*********Water check Water features in qmf_tenant")
try {
var rewrite_qmf_tenant = false
configfileString = qmf_tenant_Configfile.read()
oldConfigQmfFileString = configfileString
if (debugOutput) console.log("*********Water configfileString : " + configfileString)
var fl = configfileString.length
var n201 = configfileString.indexOf('<FT_WaterInsights_rel>')
var n202 = configfileString.indexOf('</FT_WaterInsights_rel>',n201)
console.log("*********Water oldvalue of FT_WaterInsights_rel: " + configfileString.substring(n201, n202))
if (configfileString.substring(n201, n202) != "<FT_WaterInsights_rel>1"){
rewrite_qmf_tenant = true
console.log("*********Water setting FT_WaterInsights_rel to 1 ")
var newconfigfileString = configfileString.substring(0, n201) + "<FT_WaterInsights_rel>1" + configfileString.substring(n202, configfileString.length)
configfileString = newconfigfileString
if (debugOutput) console.log("*********Water configfileString : " + configfileString)
}
else{
console.log("*********Water no need to update FT_WaterInsights_rel")
}
if (rewrite_qmf_tenant){
needRestart = true
qmf_tenant_Configfile.write(newconfigfileString)
console.log("*********Water new qmf_tenant saved")
app.popupString = "Water Features aangezet" + "..."
}
else{
console.log("*********Water no need to rewrite qmf_tenant")
app.popupString = "Water Features stonden reeds aan" + "..."
}
} catch(e) { }
break;
}
case 2: {
console.log("*********Water check usageInfo in config_happ_pwrusage.xml")
var waterfound = false
var pwrusageString = pwrusageFile.read()
var pwrusageArray = pwrusageString.split("<usageInfo>")
for (var t in pwrusageArray){
var n201 = pwrusageArray[t].indexOf('</usageInfo>')
var partOfString = pwrusageArray[t].substring(0, n201)
if (partOfString.indexOf("water")>-1){waterfound = true}
}
if (waterfound == false){
app.popupString = "Injecting usageInfo in config_happ_pwrusage.xml" + "..."
pwrusageFileBak.write(oldpwrusageString)
var firstpart = pwrusageString.split("</Config>")[0]
var newString = firstpart + usageInfo.read() + "</Config>"
pwrusageFile.write(newString)
needReboot = true
}else{
app.popupString = "Water usageInfo reeds in config_happ_pwrusage.xml" + "..."
}
break;
}
case 3: {
console.log("*********Water check billingInfo in config_happ_pwrusage.xml")
var waterfound = false
var pwrusageString = pwrusageFile.read()
var pwrusageArray = pwrusageString.split("<billingInfo>")
for (var t in pwrusageArray){
var n201 = pwrusageArray[t].indexOf('</billingInfo>')
var partOfString = pwrusageArray[t].substring(0, n201)
if (partOfString.indexOf("water")>-1){waterfound = true}
}
if (waterfound == false){
app.popupString = "Injecting billingInfo in config_happ_pwrusage.xml" + "..."
pwrusageFileBak.write(oldpwrusageString)
var firstpart = pwrusageString.split("</Config>")[0]
var newString = firstpart + billingInfo.read() + "</Config>"
pwrusageFile.write(newString)
needReboot = true
}else{
app.popupString = "Water billingInfo reeds in config_happ_pwrusage.xml" + "..."
}
break;
}
case 4: {
if (app.urlDomString != tempDomURL || app.domIdxFlow != tempdomIdxFlow || app.domIdxQuantity != tempdomIdxQuantity || app.domMode != tempDomMode || app.urlEspString != tempEspURL){
console.log("*********Water save app setting")
app.urlDomString = tempDomURL
app.domIdxFlow = tempdomIdxFlow
app.domIdxQuantity = tempdomIdxQuantity
app.domMode = tempDomMode
app.urlEspString = tempEspURL
app.saveSettings()
app.popupString = "Instellingen opgeslagen" + "..."
needRestart = true
}else{
app.popupString = "Geen veranderingen in instellingen" + "..."
}
break;
}
case 5: {
if (waterTotalChanged){
console.log("*********Water save new counter")
var http = new XMLHttpRequest()
var url = "http://" + app.urlEspString + "/setnew?" + tempTotal
http.open("GET", url, true)
http.send();
app.popupString = "Nieuwe tellerstand opgeslagen" + "..."
}
break;
}
case 6: {
if (!needRestart && !needReboot) {
console.log("*********Water no changes so no need to restart")
app.popupString = "Restart niet nodig" + "..."
app.waterRebootPopup.hide()
configChangeStep = 20
stepRunning = false
hide()
break
}
break;
}
case 7: {
if ((needRestart || needReboot)) {
console.log("*********Water creating backup of rewrite qmf_tenant ")
qmf_tenant_Configfile_bak.write(oldConfigQmfFileString)
app.popupString = "Backup van qmf_tenant maken" + "..."
}
break;
}
case 8: {
if (needRestart && !needReboot) {
console.log("*********Water restart")
console.log("*********Water restarting Toon")
app.popupString = "Herstarten van Toon" + "..."
app.waterRebootPopup.hide()
Qt.quit();
}
break;
}
case 9: {
if (needReboot) {
console.log("*********Water reboot")
console.log("*********Water restartingToon")
app.popupString = "Rebooten van Toon" + "..."
app.waterRebootPopup.hide()
app.restartToon()
}
break;
}
default: {
console.log("*********Water to default case ")
app.waterRebootPopup.hide()
configChangeStep = 20
stepRunning = false
needReboot = false
needRestart = false
hide()
break;
}
}
}
Timer {
id: stepTimer //interval to nicely save all and reboot
interval: 3000
repeat:true
running: stepRunning
triggeredOnStart: true
onTriggered: {
modRRDConfig(configChangeStep)
configChangeStep++
}
}
}