-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZwaveRepairApp.qml
More file actions
90 lines (79 loc) · 3.18 KB
/
Copy pathZwaveRepairApp.qml
File metadata and controls
90 lines (79 loc) · 3.18 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
import QtQuick 2.1
import qb.components 1.0
import qb.base 1.0;
App {
property bool debugOutput: false
property url tileUrl : "ZwaveRepairTile.qml"
property url thumbnailIcon: "qrc://apps/eMetersSettings/drawables/meteradapter.svg"
property string lastRepairTimeString: "----"
property string lastBackupTimeString: "----"
function init() {
registry.registerWidget("tile", tileUrl, this, null, {thumbLabel: qsTr("zwaveRepair"), thumbIcon: thumbnailIcon, thumbCategory: "general", thumbWeight: 30, baseTileWeight: 10, thumbIconVAlignment: "center"});
}
Timer {
id: fileCheckTimer
interval: 1800000 // 30 minute in milliseconds
//interval: 60000 // 1 minute in milliseconds
running: true
repeat: true
triggeredOnStart: true
onTriggered: checkFile()
}
Component.onCompleted: fileCheckTimer.start()
function checkFile() {
var fileName = "file:///HCBv2/config/config_hdrv_zwave.xml";
var backupFileName = "file:///HCBv2/config/config_hdrv_zwave.bak";
//var searchTerm = "<profile>ElectricityQuantityMeter</profile>";
var searchTerm = "<type>HAE_METER_";
var fileContent = loadFile(fileName);
if (fileContent.indexOf(searchTerm) !== -1) {
if (debugOutput) console.log("*********ZwaveRepair : Term found. Creating backup.");
saveFile(backupFileName, fileContent);
let lastBackupTime = new Date();
let month = String(lastBackupTime.getMonth() + 1)
let day = String(lastBackupTime.getDate())
let hours = String(lastBackupTime.getHours())
let minutes = String(lastBackupTime.getMinutes())
let customFormattedTime = day + "-" + month + " " + hours + ":" + minutes
if (debugOutput) console.log("*********ZwaveRepair : customFormattedTime: ", customFormattedTime);
lastBackupTimeString = customFormattedTime
} else {
var backupContent = loadFile(backupFileName);
if (backupContent !== null) {
if (debugOutput) console.log("*********ZwaveRepair : Term not found. Restoring from backup.");
saveFile(fileName, backupContent);
let lastRepairTime = new Date();
month = String(lastRepairTime.getMonth() + 1)
day = String(lastRepairTime.getDate())
hours = String(lastRepairTime.getHours())
minutes = String(lastRepairTime.getMinutes())
customFormattedTime = day + "-" + month + " " + hours + ":" + minutes
if (debugOutput) console.log("*********ZwaveRepair : customFormattedTime: ", customFormattedTime);
lastRepairTimeString = customFormattedTime
}
}
}
function loadFile(fileName) {
var file = fileName;
if (!file) {
if (debugOutput) console.log("*********ZwaveRepair : Failed to open file:", fileName);
return null;
}
var xhr = new XMLHttpRequest();
xhr.open("GET", fileName, false);
xhr.send();
if (xhr.status === 200) {
return xhr.responseText;
} else {
if (debugOutput) console.log("*********ZwaveRepair : Failed to load file:", fileName);
return null;
}
}
function saveFile(fileName, content) {
var saveXhr = new XMLHttpRequest();
saveXhr.open("PUT", fileName, false);
saveXhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
saveXhr.send(content);
if (debugOutput) console.log("*********ZwaveRepair : File saved:", fileName);
}
}