-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MMM-Smappee.js
106 lines (99 loc) · 3.19 KB
/
MMM-Smappee.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
/* Magic Mirror
* Module: Smappee
*
* By Christopher Fenner http://github.com/CFenner
* MIT Licensed.
*/
Module.register('MMM-Smappee', {
defaults: {
animationSpeed: 1000,
client: {
id: '',
secret: ''
},
user: {
id: '',
password: ''
},
location: {
id: '',
name: ''
},
showTimestamp: false,
updateInterval: 60000
},
// Load translations files
getTranslations: function() {
return {
en: "i18n/en.json",
de: "i18n/de.json"
};
},
//getScripts: function() {return [];},
//getStyles: function() {return [];},
getDom: function() {
var wrapper = document.createElement("div");
if (!this.loaded) {
wrapper.innerHTML = this.translate('LOADING');
return wrapper;
} else {
var moduleInfo = document.createElement('div'), valueWrapper, value;
valueWrapper = document.createElement('div');
valueWrapper.setAttribute('class', 'small');
valueWrapper.innerHTML = this.translate('CURRENT_CONSUMPTION') + ' ';
value = document.createElement('span');
value.setAttribute('class', 'wi weathericon wi-lightning bright');
valueWrapper.appendChild(value);
if(this.config.showTimestamp){
value = document.createElement('div');
value.innerHTML = moment(this.consumption.timestamp).fromNow();
valueWrapper.appendChild(value);
}
moduleInfo.appendChild(valueWrapper);
valueWrapper = document.createElement('div');
value = document.createElement('span');
value.innerHTML = this.consumption.consumption * 10 + ' W';
value.setAttribute('class', 'bright');
valueWrapper.appendChild(value);
moduleInfo.appendChild(valueWrapper);
valueWrapper = document.createElement('div');
valueWrapper.setAttribute('class', 'small');
valueWrapper.innerHTML = this.translate('PERMANENT_CONSUMPTION') + ' ';
value = document.createElement('span');
value.setAttribute('class', 'wi weathericon wi-night-clear bright');
valueWrapper.appendChild(value);
moduleInfo.appendChild(valueWrapper);
valueWrapper = document.createElement('div');
value = document.createElement('span');
value.innerHTML = this.consumption.alwaysOn + ' W';
value.setAttribute('class', 'bright');
valueWrapper.appendChild(value);
moduleInfo.appendChild(valueWrapper);
wrapper.appendChild(moduleInfo);
}
return wrapper;
},
start: function() {
Log.info('Starting module: ' + this.name);
Log.info(this.data.classes);
this.loaded = false;
this.consumption = '';
this.update(this);
},
update: function(self) {
var location = self.config.location;
self.sendSocketNotification('SMAPPEE_LOAD', self.config);
setTimeout(self.update, self.config.updateInterval, self);
},
process: function(payload){
this.consumption = payload;
this.loaded = true;
this.updateDom(this.config.animationSpeed);
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'SMAPPEE_DATA') { // && this.config.location === payload.location
Log.info('received SMAPPEE_DATA');
this.process(payload);
}
}
});