forked from paviro/MMM-PIR-Sensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-PIR-Sensor.js
80 lines (72 loc) · 2.1 KB
/
MMM-PIR-Sensor.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
/* global Module */
/* Magic Mirror
* Module: MMM-PIR-Sensor
*
* By Paul-Vincent Roll http://paulvincentroll.com
* MIT Licensed.
*/
Module.register('MMM-PIR-Sensor',{
requiresVersion: '2.1.0',
defaults: {
sensorPin: 22,
sensorState: 1,
relayPin: false,
relayState: 1,
alwaysOnPin: false,
alwaysOnState: 1,
alwaysOffPin: false,
alwaysOffState: 1,
powerSaving: true,
powerSavingDelay: 0,
powerSavingNotification: false,
powerSavingMessage: "Monitor will be turn Off by PIR module",
presenceIndicator: "fa-bullseye",
presenceIndicatorColor: "red",
presenceOffIndicator: null,
presenceOffIndicatorColor: "dimgray"
},
userPresence: false,
getStyles: function() {
return [
'font-awesome.css'
];
},
getDom: function() {
var wrapper = document.createElement("i");
if (this.userPresence) {
if (this.config.presenceIndicator && this.config.presenceIndicatorColor) {
wrapper.className = "fas " + this.config.presenceIndicator;
wrapper.style = "color: " + this.config.presenceIndicatorColor + ";";
}
}
else {
if (this.config.presenceOffIndicator && this.config.presenceOffIndicatorColor) {
wrapper.className = "fas " + this.config.presenceOffIndicator;
wrapper.style = "color: " + this.config.presenceOffIndicatorColor + ";";
}
}
return wrapper;
},
// Override socket notification handler.
socketNotificationReceived: function (notification, payload) {
if (notification === 'USER_PRESENCE') {
this.userPresence = payload;
this.sendNotification(notification, payload);
if (payload === false && this.config.powerSavingNotification === true){
this.sendNotification("SHOW_ALERT",{type:"notification", message:this.config.powerSavingMessage});
}
this.updateDom();
} else if (notification === 'SHOW_ALERT') {
this.sendNotification(notification, payload)
}
},
notificationReceived: function (notification, payload) {
if (notification === 'SCREEN_WAKEUP') {
this.sendNotification(notification, payload)
}
},
start: function () {
this.sendSocketNotification('CONFIG', this.config);
Log.info('Starting module: ' + this.name);
}
});