forked from balassy/MMM-ModuleToggleButton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-ModuleToggleButton.js
65 lines (53 loc) · 1.51 KB
/
MMM-ModuleToggleButton.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
/* global Module, MM */
/*
* MagicMirror Module: MMM-ModuleToggleButton (https://github.com/balassy/MMM-ModuleToggleButton)
* By György Balássy (https://www.linkedin.com/in/balassy)
* MIT Licensed.
*/
Module.register('MMM-ModuleToggleButton', {
defaults: {
buttonGpioPin: 6,
debounceTimeoutInMilliseconds: 500,
notificationName: 'TOGGLE_BUTTON_PRESSED',
moduleNames: [
]
},
requiresVersion: '2.1.0',
_isDisplayed: false,
start() {
this.sendSocketNotification('TOGGLE_BUTTON_CONFIG', this.config);
},
notificationReceived(notification /* , payload, sender */) {
if (notification === 'DOM_OBJECTS_CREATED') {
this._hideTargetModules();
}
},
socketNotificationReceived(notification /* , payload */) {
if (notification === this.config.notificationName) {
if (this._isDisplayed) {
this._hideTargetModules();
} else {
this._showTargetModules();
}
}
},
_hideTargetModules() {
const targetModules = this._getTargetModules();
for (let i = 0; i < targetModules.length; i++) {
const targetModule = targetModules[i];
targetModule.hide(0);
}
this._isDisplayed = false;
},
_showTargetModules() {
const targetModules = this._getTargetModules();
for (let i = 0; i < targetModules.length; i++) {
const targetModule = targetModules[i];
targetModule.show(0);
}
this._isDisplayed = true;
},
_getTargetModules() {
return MM.getModules().withClass(this.config.moduleNames);
}
});