forked from paviro/MMM-PIR-Sensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-PIR-Sensor.js
103 lines (95 loc) · 2.45 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* 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,
powerSavingOnDelay: 0,
powerSavingOffDelay: 0,
powerSavingNotification: false,
powerSavingMessage: 'Monitor will be turn Off by PIR module',
presenceIndicator: 'fa-bullseye',
presenceIndicatorColor: 'red',
presenceOffIndicator: null,
presenceOffIndicatorColor: 'dimgray',
runSimulator: false,
hideModules: false,
},
userPresence: false,
getStyles: function () {
return ['font-awesome.css', 'MMM-PIR-Sensor.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) {
switch (notification) {
case '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();
break;
case 'SHOW_ALERT':
this.sendNotification(notification, payload);
break;
case 'SCREEN_HIDE':
document.body.classList.add('screenHide');
break;
case 'SCREEN_SHOW':
document.body.classList.remove('screenHide');
break;
}
},
notificationReceived: function (notification, payload) {
if (notification === 'SCREEN_WAKEUP') {
this.sendSocketNotification(notification, payload);
}
},
start: function () {
this.sendSocketNotification('CONFIG', this.config);
Log.info('Starting module: ' + this.name);
},
});