-
Notifications
You must be signed in to change notification settings - Fork 11
/
MMM-AlexaControl.js
79 lines (72 loc) · 3.21 KB
/
MMM-AlexaControl.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
/**
* Magic Mirror
* Module: MMM-AlexaControl
*
* By JoChef2
* MIT Licensed.
*/
Module.register("MMM-AlexaControl",{
defaults:{
image: true, // shows the image
height: 265, // heigth of the image
width: 265, // width of the image
pages: 0, // number off pages in MMM-Pages module. 0 means you doesn't use it
devices: { // empty object for your custom devices
devices: []
},
notifications: [], // empty array for your notification devices
commands: [], // empty array for your command devices
startPort: 11000, // the lowest used port
refresh: true, // refresh your Mirror
restart: true, // restart your Mirror with pm2
stop: true, // stops your Mirror with pm2
reboot: false, // reboot your pi
shutdown: false, // shutdown your pi
pm2ProcessName: "mm", // name of your pm2 process
monitorToggle: true, // switch your monitor on and off
vcgencmd: 'vcgencmd', // command you use for monitor toggle
cecAddress: "0.0.0.0", // Address for the cec-client
usb: false // toggle usb power of your pi
},
getTranslations: function(){ // add more translations
return {
en: "translations/en.json",
de: "translations/de.json"
}
},
start: function(){
Log.log('Starting module: ' + this.name);
// send all translations to node_helper
this.sendSocketNotification('TRANSLATIONS', {"monitor": this.translate("MONITOR"), "shutdown": this.translate("SHUTDOWN"), "reboot": this.translate("REBOOT"), "page": this.translate("PAGE"), "refresh": this.translate("REFRESH"), "restart": this.translate("RESTART"), "stop": this.translate("STOP"), "usb": this.translate("USB"), "deviceName":this.translate(this.config.deviceName)});
this.sendSocketNotification('SET_DEVICE', this.config); // send the config to node_helper
},
getDom: function(){ // returns only an image or an empty div (necessary for MMM-Pages)
if(this.config.image){
let img = document.createElement("img");
img.classList = "img";
img.src = "MMM-AlexaControl/AlexaLogoGrey.png";
img.height = this.config.height;
img.width = this.config.width;
return img;
}else{
return document.createElement("div");
}
},
socketNotificationReceived: function(notification, payload) {
if(notification === "PAGE_CHANGED"){ // change pages of MMM-Pages
this.sendNotification("PAGE_CHANGED", payload);
}
if(notification === "ACTION"){ // refresh the Mirror
if(payload === "refresh"){
window.location.reload(true);
}
}
if(notification === "CUSTOM"){
this.sendNotification(payload[0], payload[1]); // send any notification to any module
}
if(notification =='MONITOR_ACTION'){
Log.log('RECEIVE monitor NOTIFICATION='+payload)
this.sendNotification(notification,payload)
}
}
});