forked from thomo/MMM-Pir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-Pir.js
176 lines (161 loc) · 5.18 KB
/
MMM-Pir.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
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
/*************
* MMM-Pir *
* Bugsounet *
* 03/2024 *
*************/
/* global screenDisplayer, screenTouch */
var _logPIR = (...args) => { /* do nothing */ };
Module.register("MMM-Pir", {
requiresVersion: "2.23.0",
defaults: {
debug: false,
delay: 2 * 60 * 1000,
mode: 1,
touchMode: 3,
displayCounter: true,
displayBar: true,
displayStyle: "Text",
displayLastPresence: true,
lastPresenceTimeFormat: "LL H:mm",
mode6_gpio: 20,
mode6_clearGpioValue: true,
pir_mode: 0,
pir_gpio: 21,
xrandrForceRotation: "normal",
wrandrForceRotation: "normal",
wrandrForceMode: null
},
start () {
if (this.config.debug) _logPIR = (...args) => { console.log("[MMM-Pir]", ...args); };
this.userPresence = null;
this.lastPresence = null;
this.ready = false;
let Tools = {
sendSocketNotification: (...args) => this.sendSocketNotification(...args),
hidden: () => { return this.hidden; },
translate: (...args) => this.translate(...args)
};
let displayConfig = {
displayCounter: this.config.displayCounter,
displayBar: this.config.displayBar,
displayStyle: this.config.displayStyle,
displayLastPresence: this.config.displayLastPresence,
delay: this.config.delay
};
this.screenDisplay = new screenDisplayer(displayConfig, Tools);
this.screenDisplay.checkStyle();
this.screenTouch = new screenTouch(this.config.touchMode, Tools);
_logPIR("is now started!");
},
socketNotificationReceived (notification, payload) {
switch (notification) {
case "INITIALIZED":
_logPIR("Ready to fight MagicMirror²!");
this.screenTouch.touch();
this.ready = true;
break;
case "SCREEN_SHOWING":
this.screenDisplay.screenShowing();
break;
case "SCREEN_HIDING":
this.screenDisplay.screenHiding();
break;
case "SCREEN_OUTPUT":
if (this.config.displayStyle === "Text") {
let counter = document.getElementById("MMM-PIR_SCREEN_COUNTER");
counter.textContent = payload.timer;
} else {
this.screenDisplay.barAnimate(payload.bar);
}
break;
case "SCREEN_PRESENCE":
if (!this.config.displayLastPresence) return;
if (payload) this.lastPresence = moment().format(this.config.lastPresenceTimeFormat);
else this.userPresence = this.lastPresence;
if (this.userPresence) {
let presence = document.getElementById("MMM-PIR_PRESENCE");
presence.classList.remove("hidden");
presence.classList.add("bright");
let userPresence = document.getElementById("MMM-PIR_PRESENCE_DATE");
userPresence.textContent = this.userPresence;
}
break;
case "SCREEN_POWERSTATUS":
if (payload) this.sendNotification("USER_PRESENCE", true);
else this.sendNotification("USER_PRESENCE", false);
break;
case "SCREEN_ERROR":
this.sendNotification("SHOW_ALERT", {
type: "notification",
title: "MMM-Pir",
message: `Screen Error detected: ${payload}`,
timer: 15000
});
break;
case "PIR_ERROR":
this.sendNotification("SHOW_ALERT", {
type: "notification",
title: "MMM-Pir",
message: `Pir Error detected: ${payload}`,
timer: 15000
});
break;
}
},
notificationReceived (notification, payload, sender) {
if (notification === "MODULE_DOM_CREATED") {
this.screenDisplay.prepareBar();
this.sendSocketNotification("INIT", this.config);
}
if (!this.ready) return;
switch (notification) {
case "MMM_PIR-END":
/** only available if not force-locked by touch **/
this.sendSocketNotification("FORCE_END");
break;
case "MMM_PIR-WAKEUP":
/** only available if not force-locked by touch **/
this.sendSocketNotification("WAKEUP");
break;
case "MMM_PIR-LOCK":
/** only available if not force-locked by touch **/
this.sendSocketNotification("LOCK");
break;
case "MMM_PIR-UNLOCK":
/** only available if not force-locked by touch **/
this.sendSocketNotification("UNLOCK");
break;
case "USER_PRESENCE":
/** only available if not force-locked by touch **/
if (payload) this.sendSocketNotification("WAKEUP");
else this.sendSocketNotification("FORCE_END");
}
},
getDom () {
return this.screenDisplay.prepare();
},
getStyles () {
return ["MMM-Pir.css"];
},
getScripts () {
return [
"/modules/MMM-Pir/components/progressbar.js",
"/modules/MMM-Pir/components/screenDisplayer.js",
"/modules/MMM-Pir/components/screenTouch.js",
"/modules/MMM-Pir/node_modules/long-press-event/dist/long-press-event.min.js"
];
},
getTranslations () {
return {
en: "translations/en.json",
fr: "translations/fr.json",
it: "translations/it.json",
de: "translations/de.json",
es: "translations/es.json",
nl: "translations/nl.json",
pt: "translations/pt.json",
ko: "translations/ko.json",
el: "translations/el.json"
};
}
});