-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-Yeelight.js
104 lines (93 loc) · 2.65 KB
/
MMM-Yeelight.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
MagicMirror² : Yeelight Bulb Control
=========================================
A MagicMirror² Module for controlling the Yeelight Bulb
Developer : Zulkifli Mohamed (putera)
E-mail : mr.putera@gmail.com
*/
Module.register("MMM-Yeelight", {
requiresVersion: "2.1.0",
// Default module configurations
defaults: {
lights: []
},
getTranslations: function() {
return {
"ms-my": "translations/ms-my.json",
"en": "translations/en.json"
}
},
getCommands: function(reg) {
if (reg.constructor.name == 'TelegramBotCommandRegister')
{
reg.add({
command: 'light',
description : this.translate("TELBOT_LIGHT"),
callback : 'cmd_light',
args_pattern : [/^on|off/i],
args_mapping : ['onoff']
});
}
},
cmd_light: function (command, handler) {
var text = ""; var moduleFound = 0;
// Check if MMM-Yeelight is installed on your MagicMirror
MM.getModules().enumerate((m) => {
if (m.name !== 'MMM-Yeelight') {
moduleFound = 1;
}
});
if (moduleFound == 0)
{
text = this.translate("TELBOT_LIGHT_NOT_INSTALLED");
}
else
{
if (handler.args !== null) {
var stat = handler.args['onoff'].toLowerCase();
if (stat == 'on')
{
this.sendSocketNotification('TURN_ON_LIGHT', {config: this.config, payload: {timer: 2000}});
text = this.translate("TELBOT_LIGHT_TURNING_ON");
}
else if (stat == 'off')
{
this.sendSocketNotification('TURN_OFF_LIGHT', {config: this.config, payload: {timer: 2000}});
text = this.translate("TELBOT_LIGHT_TURNING_OFF");
}
} else {
text = this.translate("TELBOT_LIGHT_SPEFICY");
}
}
handler.say("TEXT", text, {parse_mode:'Markdown'});
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'SHOW_ALERT')
{
payload.message = this.translate(payload.message);
this.sendNotification(notification, payload);
}
},
notificationReceived: function(notification, payload, sender) {
var self = this;
switch(notification)
{
case 'TURN_ON_LIGHT':
this.sendSocketNotification('TURN_ON_LIGHT', {config: this.config, payload: payload});
break;
case 'TURN_OFF_LIGHT':
this.sendSocketNotification('TURN_OFF_LIGHT', {config: this.config, payload: payload});
break;
case 'TURN_ON_LIGHT_COLOR':
this.sendSocketNotification('TURN_ON_LIGHT_COLOR', {config: this.config, payload: payload});
break;
case 'LIGHT_CHANGE_COLOR':
this.sendSocketNotification('LIGHT_CHANGE_COLOR', {config: this.config, payload: payload});
break;
case 'LIGHT_ON_FLOW':
this.sendSocketNotification('LIGHT_ON_FLOW', {config: this.config, payload: payload});
break;
default:
}
}
});