-
Notifications
You must be signed in to change notification settings - Fork 1
/
MMM-flicio.js
51 lines (48 loc) · 1.42 KB
/
MMM-flicio.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
Module.register("MMM-flicio", {
// Default module config.
defaults: {
allowQueued: true,
queueTimeout: 5,
buttons: {}
},
// the modules sends a notification to open the socket.
start: function() {
this.sendSocketNotification("START");
},
// create empty Dom object which is expected by MagicMirror
getDom: function() {
return document.createElement("div");
},
// convert socket notifications to normal notifications and use config settings
socketNotificationReceived: function(notification, payload) {
// check if message was queued and ignore if configured to.
if (
!this.config.allowQueued &&
payload.wasQueued &&
payload.queueTimeout > this.config.queueTimeout
) {
return;
}
// check if button MAC/button address is in config
if (this.config.buttons[payload.bdAddr]) {
let button = this.config.buttons[payload.bdAddr];
let messages;
if (notification == "buttonSingleOrDoubleClickOrHold") {
messages = button[payload.clickType];
} else if (
notification == "connectionStatusChanged" &&
button.connectionStatusChanged
) {
messages = {
notification: "FLICIO-connectionStatusChanged",
payload: payload
};
}
if (messages) {
for (message of messages) {
this.sendNotification(message.notification, message.payload);
}
}
}
}
});