1
|
|
|
/* Magic Mirror |
2
|
|
|
* Module: Smappee |
3
|
|
|
* |
4
|
|
|
* By Christopher Fenner http://github.com/CFenner |
5
|
|
|
* MIT Licensed. |
6
|
|
|
*/ |
7
|
|
|
Module.register('MMM-Smappee', { |
|
|
|
|
8
|
|
|
defaults: { |
9
|
|
|
animationSpeed: 1000, |
10
|
|
|
client: { |
11
|
|
|
id: '', |
12
|
|
|
secret: '' |
13
|
|
|
}, |
14
|
|
|
user: { |
15
|
|
|
id: '', |
16
|
|
|
password: '' |
17
|
|
|
}, |
18
|
|
|
location: { |
19
|
|
|
id: '', |
20
|
|
|
name: '' |
21
|
|
|
}, |
22
|
|
|
showTimestamp: false, |
23
|
|
|
updateInterval: 60000 |
24
|
|
|
}, |
25
|
|
|
// Load translations files |
26
|
|
|
getTranslations: function() { |
27
|
|
|
return { |
28
|
|
|
en: "i18n/en.json", |
29
|
|
|
de: "i18n/de.json" |
30
|
|
|
}; |
31
|
|
|
}, |
32
|
|
|
//getScripts: function() {return [];}, |
33
|
|
|
//getStyles: function() {return [];}, |
34
|
|
|
getDom: function() { |
35
|
|
|
var wrapper = document.createElement("div"); |
36
|
|
|
|
37
|
|
|
if (!this.loaded) { |
38
|
|
|
wrapper.innerHTML = this.translate('LOADING'); |
39
|
|
|
return wrapper; |
40
|
|
|
} else { |
41
|
|
|
var moduleInfo = document.createElement('div'), valueWrapper, value; |
42
|
|
|
|
43
|
|
|
valueWrapper = document.createElement('div'); |
44
|
|
|
valueWrapper.setAttribute('class', 'small'); |
45
|
|
|
valueWrapper.innerHTML = this.translate('CURRENT_CONSUMPTION') + ' '; |
46
|
|
|
value = document.createElement('span'); |
47
|
|
|
value.setAttribute('class', 'wi weathericon wi-lightning bright'); |
48
|
|
|
valueWrapper.appendChild(value); |
49
|
|
|
if(this.config.showTimestamp){ |
50
|
|
|
value = document.createElement('div'); |
51
|
|
|
value.innerHTML = moment(this.consumption.timestamp).fromNow(); |
52
|
|
|
valueWrapper.appendChild(value); |
53
|
|
|
} |
54
|
|
|
moduleInfo.appendChild(valueWrapper); |
55
|
|
|
|
56
|
|
|
valueWrapper = document.createElement('div'); |
57
|
|
|
value = document.createElement('span'); |
58
|
|
|
value.innerHTML = this.consumption.consumption * 10 + ' W'; |
59
|
|
|
value.setAttribute('class', 'bright'); |
60
|
|
|
valueWrapper.appendChild(value); |
61
|
|
|
moduleInfo.appendChild(valueWrapper); |
62
|
|
|
|
63
|
|
|
valueWrapper = document.createElement('div'); |
64
|
|
|
valueWrapper.setAttribute('class', 'small'); |
65
|
|
|
valueWrapper.innerHTML = this.translate('PERMANENT_CONSUMPTION') + ' '; |
66
|
|
|
value = document.createElement('span'); |
67
|
|
|
value.setAttribute('class', 'wi weathericon wi-night-clear bright'); |
68
|
|
|
valueWrapper.appendChild(value); |
69
|
|
|
moduleInfo.appendChild(valueWrapper); |
70
|
|
|
|
71
|
|
|
valueWrapper = document.createElement('div'); |
72
|
|
|
value = document.createElement('span'); |
73
|
|
|
value.innerHTML = this.consumption.alwaysOn + ' W'; |
74
|
|
|
value.setAttribute('class', 'bright'); |
75
|
|
|
valueWrapper.appendChild(value); |
76
|
|
|
moduleInfo.appendChild(valueWrapper); |
77
|
|
|
|
78
|
|
|
wrapper.appendChild(moduleInfo); |
79
|
|
|
} |
80
|
|
|
return wrapper; |
81
|
|
|
}, |
82
|
|
|
start: function() { |
83
|
|
|
Log.info('Starting module: ' + this.name); |
|
|
|
|
84
|
|
|
Log.info(this.data.classes); |
85
|
|
|
this.loaded = false; |
86
|
|
|
this.consumption = ''; |
87
|
|
|
this.update(this); |
88
|
|
|
}, |
89
|
|
|
update: function(self) { |
90
|
|
|
var location = self.config.location; |
|
|
|
|
91
|
|
|
self.sendSocketNotification('SMAPPEE_LOAD', self.config); |
92
|
|
|
setTimeout(self.update, self.config.updateInterval, self); |
93
|
|
|
}, |
94
|
|
|
process: function(payload){ |
95
|
|
|
this.consumption = payload; |
96
|
|
|
this.loaded = true; |
97
|
|
|
this.updateDom(this.config.animationSpeed); |
98
|
|
|
}, |
99
|
|
|
socketNotificationReceived: function(notification, payload) { |
100
|
|
|
if (notification === 'SMAPPEE_DATA') { // && this.config.location === payload.location |
101
|
|
|
Log.info('received SMAPPEE_DATA'); |
|
|
|
|
102
|
|
|
|
103
|
|
|
this.process(payload); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
}); |
107
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.