-
Notifications
You must be signed in to change notification settings - Fork 11
/
node_helper.js
80 lines (74 loc) · 1.96 KB
/
node_helper.js
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
const NodeHelper = require("node_helper");
const exec = require("child_process").exec;
const Log = require("../../js/logger");
module.exports = NodeHelper.create({
/**
*
*/
start: function () {
this.isMonitorOn(function (result) {
Log.info("MMM-MotionDetector: monitor is " + (result ? "ON" : "OFF") + ".");
});
},
/**
*
*/
activateMonitor: function () {
this.isMonitorOn(function (result) {
if (!result) {
exec("vcgencmd display_power 1", function (err, out, code) {
if (err) {
Log.error("MMM-MotionDetector: error activating monitor: " + code);
} else {
Log.info("MMM-MotionDetector: monitor has been activated.");
}
});
}
});
},
/**
*
*/
deactivateMonitor: function () {
this.isMonitorOn(function (result) {
if (result) {
exec("vcgencmd display_power 0", function (err, out, code) {
if (err) {
Log.error("MMM-MotionDetector: error deactivating monitor: " + code);
} else {
Log.info("MMM-MotionDetector: monitor has been deactivated.");
}
});
}
});
},
/**
*
* @param resultCallback
*/
isMonitorOn: function (resultCallback) {
exec("vcgencmd display_power", function (err, out, code) {
if (err) {
Log.error("MMM-MotionDetector: error calling monitor status: " + code);
return;
}
Log.info("MMM-MotionDetector: monitor status is " + out);
resultCallback(out.includes("=1"));
});
},
/**
*
* @param notification
* @param payload
*/
socketNotificationReceived: function (notification, payload) {
if (notification === "ACTIVATE_MONITOR") {
Log.info("MMM-MotionDetector: activating monitor.");
this.activateMonitor();
}
if (notification === "DEACTIVATE_MONITOR") {
Log.info("MMM-MotionDetector: deactivating monitor.");
this.deactivateMonitor();
}
},
});