-
Notifications
You must be signed in to change notification settings - Fork 5
/
Shelly-HT.js
68 lines (66 loc) · 2.32 KB
/
Shelly-HT.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
Module.register("Shelly-HT",{
// Default module config.
defaults: {
//Just a mock API I used for development
ShellyHTApiPath: "http://www.mocky.io/v2/5e9999183300003e267b2744",
RefreshInterval: 3000,
displayUpdated: true,
horizontalView: true
},
//After startup, we don't have data and might not have it for a long time, until Shelly HT wakes up.
ShellyHTData: {
tmp: "--",
hum: "--",
bat: "--",
updated: "--"
},
getStyles: function () {
return ["Shelly-HT.css", "font-awesome.css"];
},
start: function() {
var self = this;
// Schedule update timer.
setInterval(function() {
self.sendSocketNotification("GetShelly", self.config.ShellyHTApiPath);
self.updateDom();
//TODO: make the refresh interval configurable. Every 3 secs seems like an overkill
}, this.config.RefreshInterval);
},
socketNotificationReceived: function (notification, payload) {
if (notification = "ShellyHTData"){
//Log.log(this.name + " received a socket notification: " + notification + " - Temp: " + payload.tmp + " Hum: " + payload.hum + "Updated: " + payload.updated);
this.ShellyHTData.tmp = payload.tmp
this.ShellyHTData.hum = payload.hum
this.ShellyHTData.bat = payload.bat
this.ShellyHTData.updated = payload.updated
}
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");
var tmp = this.translate("TEMPERATURE");
var hum = this.translate("HUMIDITY");
var bat = this.translate("BATTERY", {"bat": this.ShellyHTData.bat})
var updated = this.translate("UPDATED", {"upd": this.ShellyHTData.updated})
ihtml = "<div class='container'>"
if (this.config.horizontalView) {
ihtml += " <div class='right'><sup>" + hum + "</sup> " + this.ShellyHTData.hum + " %</div>"
ihtml += " <div class='right'><sup>" + tmp + "</sup> " + this.ShellyHTData.tmp + " ℃</div>"
} else {
ihtml += " <div class='newline'><sup>" + hum + "</sup>" + this.ShellyHTData.hum + " %</div>"
ihtml += " <div class='newline'><sup>" + tmp + "</sup>" + this.ShellyHTData.tmp + " ℃</div>"
}
if (this.config.displayUpdated){
ihtml += " <p class='bottom'>" + bat + " " + updated + "</p>"
}
ihtml += "</div>"
wrapper.innerHTML = ihtml
return wrapper
},
getTranslations: function() {
return {
nl: 'translations/nl.json',
en: 'translations/en.json'
};
}
});