-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDomoticzboardApp.qml
380 lines (337 loc) · 10.6 KB
/
DomoticzboardApp.qml
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
import QtQuick 1.1
import qb.components 1.0
import qb.base 1.0;
App {
id: root
property url trayUrl : "DomoticzboardTray.qml";
property url thumbnailIcon: "./drawables/DomoticzSystrayIcon.png"
property url menuScreenUrl : "DomoticzboardSettings.qml"
property url domoticzScreenUrl : "DomoticzboardScreen.qml"
property DomoticzboardSettings domoticzSettings
property SystrayIcon domoticzTray
property bool showDBIcon : true
property string timeStr
property string dateStr
property string connectionPath
property string ipadres
property string poortnummer
property string connectionPathSwitch: "";
property string bulb_offvar: "./drawables/Light48_Off.png";
property string bulb_onvar: "./drawables/Light48_On.png";
property string group_offvar: "./drawables/GroupOff.png";
property string group_onvar: "./drawables/GroupOn.png";
property string switch1idx : "0"
property string switch1StatusIcon
property string switch1Name
property string switch2idx : "0"
property string switch2StatusIcon
property string switch2Name
property string switch3idx : "0"
property string switch3StatusIcon
property string switch3Name
property string switch4idx : "0"
property string switch4StatusIcon
property string switch4Name
property string switch5idx : "0"
property string switch5StatusIcon
property string switch5Name
property string scene1idx
property string scene1StatusName
property string scene1StatusIcon
property string scene1Name
property string scene2idx
property string scene2StatusName
property string scene2StatusIcon
property string scene2Name
property string scene3idx
property string scene3StatusName
property string scene3StatusIcon
property string scene3Name
property string scene4idx
property string scene4StatusName
property string scene4StatusIcon
property string scene4Name
property string scene5idx
property string scene5StatusName
property string scene5StatusIcon
property string scene5Name
function init() {
registry.registerWidget("systrayIcon", trayUrl, this, "domoticzTray");
registry.registerWidget("screen", domoticzScreenUrl, this);
registry.registerWidget("screen", menuScreenUrl, this, "domoticzSettings");
registry.registerWidget("menuItem", null, this, null, {objectName: "DBMenuItem", label: qsTr("DB-settings"), image: thumbnailIcon, screenUrl: menuScreenUrl, weight: 120});
}
//this function needs to be started after the app is booted.
Component.onCompleted: {
refreshScreen();
}
function refreshScreen() {
readDBState();
readConnection();
readSwitch();
datetimeTimer.start();
}
//this is the save of the toggle which could be found in the menuscreen.
function saveshowDBIcon(text) {
showDBIcon = (text == "Yes");
var doc2 = new XMLHttpRequest();
doc2.open("PUT", "file:///HCBv2/qml/apps/domoticzboard/ShowDBIcon.txt");
doc2.send(showDBIcon);
if (showDBIcon) {
domoticzTray.show();
} else {
domoticzTray.hide();
}
}
//In this read function you'll find the execution of the visibility of the systray icon.
function readDBState() {
var doc3 = new XMLHttpRequest();
doc3.onreadystatechange = function() {
if (doc3.readyState == XMLHttpRequest.DONE) {
if (doc3.responseText.length > 2) {
showDBIcon = (doc3.responseText == "true");
if (showDBIcon) {
domoticzTray.show();
} else {
domoticzTray.hide();
}
}
}
}
doc3.open("GET", "file:///HCBv2/qml/apps/domoticzboard/ShowDBIcon.txt", true);
doc3.send();
}
//this read function will show you the correct information after a reboot of your toon device, it will receive the information of the serverip.txt file.
function readConnection() {
var doc2 = new XMLHttpRequest();
doc2.onreadystatechange = function() {
if (doc2.readyState == XMLHttpRequest.DONE) {
if (doc2.responseText.length > 2) {
connectionPath = doc2.responseText;
if (connectionPath.length > 0) {
var pathVar = connectionPath;
var splitVar = pathVar.split(":")
ipadres = splitVar[0];
poortnummer = splitVar[1];
}
}
}
}
doc2.open("GET", "file:///HCBv2/qml/apps/domoticzboard/serverip.txt", true);
doc2.send();
}
function readSwitch() {
var doc1 = new XMLHttpRequest();
doc1.onreadystatechange = function() {
if (doc1.readyState == XMLHttpRequest.DONE) {
if (doc1.responseText.length > 2) {
connectionPathSwitch = doc1.responseText;
if (connectionPathSwitch.length > 0) {
var splitVar = connectionPathSwitch.split(",");
if (splitVar[0].length > 0) switch1idx = splitVar[0];
if (splitVar[1].length > 0) switch2idx = splitVar[1];
if (splitVar[2].length > 0) switch3idx = splitVar[2];
if (splitVar[3].length > 0) switch4idx = splitVar[3];
if (splitVar[4].length > 0) switch5idx = splitVar[4];
}
}
}
}
doc1.open("GET", "file:///HCBv2/qml/apps/domoticzboard/switch.txt", true);
doc1.send();
}
function readDeviceStatus1(idx) {
var xmlhttp = new XMLHttpRequest();
var i;
var j;
var tmpDeviceStatus1;
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var res = xmlhttp.responseText;
i = res.indexOf('"Name"');
j = res.indexOf('"', i+10);
if (idx == switch1idx) {
switch1Name = res.substring(i+10 , j);
} else if (idx == switch2idx) {
switch2Name = res.substring(i+10 , j);
} else if (idx == switch3idx) {
switch3Name = res.substring(i+10 , j);
} else if (idx == switch4idx) {
switch4Name = res.substring(i+10 , j);
} else if (idx == switch5idx) {
switch5Name = res.substring(i+10 , j);
}
i = res.indexOf('"Status"', j);
j = res.indexOf('"', i+12);
tmpDeviceStatus1 = res.substring(i+12, j);
if (idx == switch1idx) {
if (tmpDeviceStatus1 == "On") {
switch1StatusIcon = bulb_onvar;
} else {
switch1StatusIcon = bulb_offvar;
}
} else if (idx == switch2idx) {
if (tmpDeviceStatus1 == "On") {
switch2StatusIcon = bulb_onvar;
} else {
switch2StatusIcon = bulb_offvar;
}
} else if (idx == switch3idx) {
if (tmpDeviceStatus1 == "On") {
switch3StatusIcon = bulb_onvar;
} else {
switch3StatusIcon = bulb_offvar;
}
} else if (idx == switch4idx) {
if (tmpDeviceStatus1 == "On") {
switch4StatusIcon = bulb_onvar;
} else {
switch4StatusIcon = bulb_offvar;
}
} else if (idx == switch5idx){
if (tmpDeviceStatus5 == "On") {
switch5StatusIcon = bulb_onvar;
} else {
switch5StatusIcon = bulb_offvar;
}
}
}
}
}
xmlhttp.open("GET", "http://"+connectionPath+"/json.htm?type=devices&rid="+idx, true);
xmlhttp.send();
}
function readSceneStatus() {
var xmlhttp = new XMLHttpRequest();
var i;
var j;
var k;
//var tmpSceneStatus1;
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var res = xmlhttp.responseText;
//scene1 json
i = res.indexOf('"idx"');
j = res.indexOf('"', i+9);
k = res.indexOf('"', i+9);
scene1idx = res.substring(i+9, j);
i = res.indexOf('"Name"');
j = res.indexOf('"', i+10);
scene1Name = res.substring(i+10 , j);
i = res.indexOf('"Status"', j);
j = res.indexOf('"', i+12);
scene1StatusName = res.substring(i+12, j);
if (scene1idx == "1") {
if (scene1StatusName == "On") {
scene1StatusIcon = group_offvar;
} else if (scene1StatusName == "Off") {
scene1StatusIcon = group_onvar;
} else {
scene1StatusIcon = group_offvar;
}
}
//scene2 json
res = res.slice(k)
i = res.indexOf('"idx"');
j = res.indexOf('"', i+9);
k = res.indexOf('"', i+9);
scene2idx = res.substring(i+9, j);
i = res.indexOf('"Name"');
j = res.indexOf('"', i+10);
scene2Name = res.substring(i+10 , j);
i = res.indexOf('"Status"', j);
j = res.indexOf('"', i+12);
scene2StatusName = res.substring(i+12, j);
if (scene2idx == "2") {
if (scene2StatusName == "On") {
scene2StatusIcon = group_offvar;
} else if (scene2StatusName == "Off") {
scene2StatusIcon = group_onvar;
} else {
scene2StatusIcon = group_offvar;
}
}
//scene3 json
res = res.slice(k)
i = res.indexOf('"idx"');
j = res.indexOf('"', i+9);
scene3idx = res.substring(i+9, j);
i = res.indexOf('"Name"');
j = res.indexOf('"', i+10);
scene3Name = res.substring(i+10 , j);
i = res.indexOf('"Status"', j);
j = res.indexOf('"', i+12);
scene3StatusName = res.substring(i+12, j);
if (scene3idx == "3") {
if (scene3StatusName == "On") {
scene3StatusIcon = group_offvar;
} else if (scene3StatusName == "Off") {
scene3StatusIcon = group_onvar;
} else {
scene3StatusIcon = group_offvar;
}
}
//scene4 json
res = res.slice(k)
i = res.indexOf('"idx"');
j = res.indexOf('"', i+9);
scene4idx = res.substring(i+9, j);
i = res.indexOf('"Name"');
j = res.indexOf('"', i+10);
scene4Name = res.substring(i+10 , j);
i = res.indexOf('"Status"', j);
j = res.indexOf('"', i+12);
scene4StatusName = res.substring(i+12, j);
if (scene4idx == "4") {
if (scene4StatusName == "On") {
scene4StatusIcon = group_offvar;
} else if (scene4StatusName == "Off") {
scene4StatusIcon = group_onvar;
} else {
scene4StatusIcon = group_offvar;
}
}
//scene5 json
res = res.slice(k)
i = res.indexOf('"idx"');
j = res.indexOf('"', i+9);
scene5idx = res.substring(i+9, j);
i = res.indexOf('"Name"');
j = res.indexOf('"', i+10);
scene5Name = res.substring(i+10 , j);
i = res.indexOf('"Status"', j);
j = res.indexOf('"', i+12);
scene5StatusName = res.substring(i+12, j);
if (scene5idx == "5") {
if (scene5StatusName == "On") {
scene5StatusIcon = group_offvar;
} else if (scene5StatusName == "Off") {
scene5StatusIcon = group_onvar;
} else {
scene5StatusIcon = group_offvar;
}
}
//ending tags
}
}
}
xmlhttp.open("GET", "http://"+connectionPath+"/json.htm?type=scenes", true);
xmlhttp.send();
}
Timer {
id: datetimeTimer
interval: 10000
running: false
repeat: true
onTriggered: {
if (switch1idx !== "0") readDeviceStatus1(switch1idx);
if (switch2idx !== "0") readDeviceStatus1(switch2idx);
if (switch3idx !== "0") readDeviceStatus1(switch3idx);
if (switch4idx !== "0") readDeviceStatus1(switch4idx);
if (switch5idx !== "0") readDeviceStatus1(switch5idx);
readSceneStatus();
}
}
}