-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMMM-DHT-Sensors.js
91 lines (73 loc) · 2.32 KB
/
MMM-DHT-Sensors.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
/* global Module */
/* Magic Mirror
* Module: MMM-DHT-Sensors
*
* By Stefan Krause http://yawns.de
* MIT Licensed.
*/
Module.register('MMM-DHT-Sensors',{
defaults: {
sensorPIN: 18,
sensorType: "11", //DHT11 = 11, DHT22/AM2302 = 22
units: config.units,
animationSpeed: 1000,
refreshInterval: 50000,
},
start: function() {
Log.info('Starting module: ' + this.name);
this.loaded = false;
this.temperature = null;
this.humidity = null;
this.sendSocketNotification('CONFIG', this.config);
},
getDom: function() {
var wrapper = document.createElement("div");
if (!this.loaded) {
wrapper.innerHTML = this.translate('LOADING');
wrapper.className = "dimmed light small";
return wrapper;
}
wrapper.className = "small";
var spacer = document.createElement("span");
spacer.innerHTML = " ";
if (this.temperature != null) {
var temperature_symbol = document.createElement("span");
if (this.temperature >= 30) {
temperature_symbol.className = "fa fa-thermometer-full";
} else if (this.temperature >= 20) {
temperature_symbol.className = "fa fa-thermometer-three-quarters";
} else if (this.temperature >= 10) {
temperature_symbol.className = "fa fa-thermometer-half";
} else if (this.temperature >= 0) {
temperature_symbol.className = "fa fa-thermometer-quarter";
} else {
temperature_symbol.className = "fa fa-thermometer-empty";
}
wrapper.appendChild(temperature_symbol);
var temperature_text = document.createElement("span");
temperature_text.innerHTML = " " + this.temperature + "°";
wrapper.appendChild(temperature_text);
}
wrapper.appendChild(spacer);
if (this.humidity != null) {
var humidity_symbol = document.createElement("span");
humidity_symbol.className = "fa fa-tint";
wrapper.appendChild(humidity_symbol);
var humidity_text = document.createElement("span");
humidity_text.innerHTML = " " + this.humidity + "%";
wrapper.appendChild(humidity_text);
}
return wrapper;
},
socketNotificationReceived: function(notification, payload) {
if (notification === "STARTED") {
this.loaded = true;
this.updateDom();
}
else if (notification === "DATA") {
this.temperature = payload.temperature;
this.humidity = payload.humidity;
this.updateDom();
}
}
});