-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-HomeConnect.js
138 lines (111 loc) · 4.87 KB
/
MMM-HomeConnect.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
Module.register("MMM-HomeConnect", {
// define variables used by module, but not in config data
updated: 0,
HTML: "<p>Loading Module...</p>",
// holder for config info from module_name.js
config:null,
// anything here in defaults will be added to the config data
// and replaced if the same thing is provided in config
defaults: {
client_ID: "",
client_Secret: "",
BaseURL: 'https://api.home-connect.com/api',
showDeviceIcon: true, //Show or hide the icon of the devices
showAlwaysAllDevices: false, //if true all devices will be shown, despite if on or off
showDeviceIfDoorIsOpen: true, //if showAlwaysAllDevices is true, the device will be shown if Door is open
showDeviceIfFailure: true, //if showAlwaysAllDevices is true, the device will be shown if there is a failure
showDeviceIfInfoIsAvailable: true, //if showAlwaysAllDevices is true, the device will be shown if Info is Available
updateFrequency: 1000*60*60
},
init: function(){
Log.log(this.name + " is in init!");
},
start: function(){
Log.log(this.name + " is starting!");
var timer = setInterval(()=>{
this.sendSocketNotification("UPDATEREQUEST", null);
}, this.config.updateFrequency);
},
loaded: function(callback) {
Log.log(this.name + " is loaded!");
callback();
},
// return list of other functional scripts to use, if any (like require in node_helper)
getScripts: function() {
return [
// sample of list of files to specify here, if no files,do not use this routine, or return empty list
//'script.js', // will try to load it from the vendor folder, otherwise it will load is from the module folder.
//'moment.js', // this file is available in the vendor folder, so it doesn't need to be available in the module folder.
//this.file('anotherfile.js'), // this file will be loaded straight from the module folder.
//'https://code.jquery.com/jquery-2.2.3.min.js', // this file will be loaded from the jquery servers.
]
},
// return list of stylesheet files to use if any
getStyles: function() {
return ["MMM-HomeConnect.css"];
//return [
// sample of list of files to specify here, if no files, do not use this routine, , or return empty list
//'script.css', // will try to load it from the vendor folder, otherwise it will load is from the module folder.
//'font-awesome.css', // this file is available in the vendor folder, so it doesn't need to be avialable in the module folder.
//this.file('anotherfile.css'), // this file will be loaded straight from the module folder.
//'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css', // this file will be loaded from the bootstrapcdn servers.
//]
},
// return list of translation files to use, if any
/*getTranslations: function() {
return {
// sample of list of files to specify here, if no files, do not use this routine, , or return empty list
// en: "translations/en.json", (folders and filenames in your module folder)
// de: "translations/de.json"
}
}, */
// only called if the module header was configured in module config in config.js
getHeader: function() {
return "Home Connect";
},
// messages received from other modules and the system (NOT from your node helper)
// payload is a notification dependent data structure
notificationReceived: function(notification, payload, sender) {
// once everybody is loaded up
if(notification==="ALL_MODULES_STARTED"){
// send our config to our node_helper
this.sendSocketNotification("CONFIG",this.config)
}
if (sender) {
//Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
} else {
//Log.log(this.name + " received a system notification: " + notification);
}
},
// messages received from from your node helper (NOT other modules or the system)
// payload is a notification dependent data structure, up to you to design between module and node_helper
socketNotificationReceived: function(notification, payload) {
//Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
switch(notification){
case "STARTUP":
this.HTML = payload;
//some_other_variable = payload;
this.updateDom(1000);
break;
case "MMM-HomeConnect_Update":
this.HTML = payload;
this.updateDom();
//some_other_variable = payload;
break;
}
},
// system notification your module is being hidden
// typically you would stop doing UI updates (getDom/updateDom) if the module is hidden
suspend: function(){
},
// system notification your module is being unhidden/shown
// typically you would resume doing UI updates (getDom/updateDom) if the module is shown
resume: function(){
},
// this is the major worker of the module, it provides the displayable content for this module
getDom: function() {
var wrapper = document.createElement("div");
wrapper.innerHTML = this.HTML;
return wrapper;
},
})