-
Notifications
You must be signed in to change notification settings - Fork 4
/
MMM-Pins.js
47 lines (44 loc) · 1.3 KB
/
MMM-Pins.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
/* global Module */
/* Magic Mirror
* Module: MMM-Pins
*
* MIT Licensed.
*/
Module.register('MMM-Pins',{
requiresVersion: "2.1.0",
defaults: {
pinConfiguration: []
},
// Override notification handler.
notificationReceived: function(notification, payload) {
if(notification === "ALL_MODULES_STARTED"){
this.sendSocketNotification('PIN_CONFIG', this.config.pinConfiguration)
let payload = {
module: this.name,
path: "pins",
actions: {}
};
for (let index = 0; index < this.config.pinConfiguration.length; ++index) {
let pinConfig = this.config.pinConfiguration[index];
payload.actions[pinConfig.notification] = {notification: pinConfig.notification, prettyName: pinConfig.prettyName};
}
Log.log(payload.module);
Log.log(payload.actions.toString());
this.sendNotification("REGISTER_API", payload);
return;
}
for (let index = 0; index < this.config.pinConfiguration.length; ++index) {
let pinConfig = this.config.pinConfiguration[index];
if(pinConfig.notification === notification){
this.sendSocketNotification("TOGGLE_PIN", pinConfig.pin);
if(pinConfig.sound){
this.sendNotification('PLAY_SOUND', pinConfig.sound);
}
break;
}
}
},
start: function() {
Log.info('Starting module: ' + this.name);
}
});