-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMMM-Homematic-Rooms.js
136 lines (98 loc) · 3.53 KB
/
MMM-Homematic-Rooms.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
Module.register('MMM-Homematic-Rooms',
{
defaults: {
homematicURL: "10.0.0.5"
},
getStyles: function () {
return ['modules/MMM-Homematic-Rooms/css/MMM-Homematic-Rooms.css'];
},
getTranslations: function () {
return
{
en: "translations/en.json"
}
},
// Notification from node_helper.js.
// The standings are received here. Then module is redrawn.
// @param notification - Notification type.
// @param payload - Contains an array of teams. Each team contains position, name, points etc...
socketNotificationReceived: function (notification, payload) {
var self = this;
if (notification === 'SET_DEVICES') {
this.devices = payload;
this.sendSocketNotification('GET_ROOMS', {});
}
else if (notification === 'SET_ROOMS') {
this.rooms = payload;
this.sendSocketNotification('GET_TEMPERATURE', {});
}
else if (notification === 'SET_TEMPERATURE') {
this.sendSocketNotification('GET_DATA', {});
}
else if (notification === 'SET_DATA') {
this.rooms = payload;
this.updateDom(0);
}
},
// Override dom generator.
getDom: function () {
var wrapper = document.createElement('table');
if (this.rooms.length === 0) {
wrapper.innerHTML = this.translate('Initializing MMM-Homematic');
wrapper.className = 'dimmed xsmall';
return wrapper;
}
wrapper.className = 'bright xsmall';
for (var i = 0; i < this.rooms.length; ++i) {
var evenRow = (i % 2 == 0);
var row = document.createElement('tr');
row.className = evenRow ? 'evenrow' : 'oddrow';
var imageColumn = document.createElement("TD");
imageColumn.className = "imageColumn";
var img = new Image(30, 30);
img.src = 'https://visualpharm.com/assets/686/Room-595b40b85ba036ed117da28a.svg';
imageColumn.appendChild(img);
row.appendChild(imageColumn);
var room = this.rooms[i];
var td = document.createElement('TD');
td.appendChild(document.createTextNode(room.name));
td.appendChild(document.createElement("hr"));
for (let j = 0; j < room.temperature.length; j++) {
let heaterImg = new Image(20, 20);
heaterImg.src = this.file("/img/heater_on.svg");
td.appendChild(heaterImg);
}
// td.appendChild(document.createElement("br"));
// td.appendChild(document.createTextNode(room.sensors.length + " sensors"));
row.appendChild(td);
try {
var tempcolumn = document.createElement('TD');
tempcolumn.width = '50';
tempcolumn.appendChild(document.createTextNode(room.temperature[0].actualTemperature)); //Showing the temperature of the first found entity if set
row.appendChild(tempcolumn);
// var destTempcolumn = document.createElement('TD');
// destTempcolumn.width = '50';
// destTempcolumn.appendChild(document.createTextNode(room.temperature[0].setTemperature)); //Showing the temperature of the first found entity if set
// row.appendChild(destTempcolumn);
}
catch (error) {
console.log("error");
}
wrapper.appendChild(row);
}
return wrapper;
},
// Override start to init stuff.
start: function () {
this.devices = [];
this.rooms = [];
// Tell node_helper to load standings at startup.
this.sendSocketNotification('SET_CONNECTION', this.config.homematicURL);
this.sendSocketNotification('GET_DEVICES', {});
// Make sure standings are reloaded every 10 minutes.
var self = this;
setInterval(function () {
self.sendSocketNotification('GET_DEVICES', {});
}, 10 * 60 * 1000); // In millisecs. Refresh every 10 minutes.
},
});