-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
MMM-AlexaOnOff.js
executable file
·62 lines (54 loc) · 1.87 KB
/
MMM-AlexaOnOff.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
/* global Module */
/* Magic Mirror
* Module: MMM-AlexaOnOff
*
* By shbatm
* MIT Licensed.
*/
/* jshint esversion:6 */
Module.register("MMM-AlexaOnOff", {
defaults: {
netInterface: "wlan0",
netProtocol: "IPv4",
startPort: 21900,
devices: [
"Magic Mirror",
]
},
requiresVersion: "2.5.0", // Required version of MagicMirror
start: function() {
this.sendSocketNotification("INITIALIZE", this.config);
},
getScripts: function() {
return [];
},
getStyles: function() {
return [];
},
socketNotificationReceived: function(notification, payload) {
if (notification === "ACTION_RECEIVED") {
this.config.devices.forEach(d => {
if (typeof d === "object" && payload.device === d.name) {
if (payload.action in d) {
if (Object.prototype.toString.call(d[payload.action]) === '[object Array]') {
// Array of notifications present
d[payload.action].forEach(n => {
this.sendNotification(n.notification, n.payload);
});
} else {
// Single notification present
this.sendNotification(d[payload.action].notification, d[payload.action].payload);
}
} else {
this.sendNotification("MMM-AlexaOnOff_ACTION_RECEIVED", payload);
}
} else if (typeof d === "string" && payload.device === d) {
this.sendNotification("MMM-AlexaOnOff_ACTION_RECEIVED", payload);
}
});
}
},
notificationReceived: function(notification, payload, sender) {
// Do nothing.
},
});