first working implementation.
BrainDoctor committed
Jul 8, 2017 at 13:50 UTC
5cd2d2e3ffff024305e1f3f842c2e6496e7a6be8
2 files changed
+73
-52
node.d/stiebeleltron.node.js
+56
-51
@@ -19,18 +19,18 @@ var stiebeleltron = {
19
charts: {},
20
pages: {},
21
22
- createBasicDimension(id, name) {
22
+ createBasicDimension: function (id, name, multiplier, divisor) {
23
return {
24
id: id, // the unique id of the dimension
25
name: name, // the name of the dimension
26
algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
27
- multiplier: 1, // the multiplier
28
- divisor: 1, // the divisor
27
+ multiplier: multiplier, // the multiplier
28
+ divisor: divisor, // the divisor
29
hidden: false // is hidden (boolean)
30
};
31
},
32
33
- processResponse(service, html) {
33
+ processResponse: function (service, html) {
34
if (html === null) return;
35
36
// add the service
@@ -45,14 +45,15 @@ var stiebeleltron = {
45
html: html,
46
service: service,
47
category: category,
48
- page: page
48
+ page: page,
49
+ chartDefinition: null
50
};
51
stiebeleltron.processCategory(context);
52
53
}
54
},
55
55
- processCategory(context) {
56
+ processCategory: function (context) {
57
var charts = context.category.charts;
58
var chartCount = charts.length;
59
while (chartCount--) {
@@ -63,7 +64,7 @@ var stiebeleltron = {
64
},
65
66
66
- processChart(context) {
67
+ processChart: function (context) {
68
var dimensions = context.chartDefinition.dimensions;
69
var dimensionCount = dimensions.length;
70
context.service.begin(stiebeleltron.getChartUsing(context));
@@ -75,45 +76,37 @@ var stiebeleltron = {
76
context.service.end();
77
},
78
78
- getChartUsing(context) {
79
- var chartId = "stiebeleltron_" + context.page.id +
80
- "." + context.category.id +
81
- "." + context.chartDefinition.id;
79
+ getChartUsing: function (context) {
80
+ var chartId = this.getChartId(context);
81
var chart = stiebeleltron.charts[chartId];
82
if (stiebeleltron.isDefined(chart)) return chart;
83
85
- var dim = {};
86
-
87
- var inverter_count = Object.keys(inverters).length;
88
- var inverter = inverters[inverter_count.toString()];
89
- var i = 1;
90
- for (i; i <= inverter_count; i++) {
91
- if (stiebeleltron.isUndefined(inverter)) {
92
- netdata.error("Expected an Inverter with a numerical name! " +
93
- "Have a look at your JSON output to verify.");
94
- continue;
95
- }
96
- dim[i.toString()] = {
97
- id: 'inverter_' + i, // the unique id of the dimension
98
- name: 'Inverter ' + i, // the name of the dimension
99
- algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
100
- multiplier: 1, // the multiplier
101
- divisor: 1000, // the divisor
102
- hidden: false // is hidden (boolean)
103
- };
84
+ var chartDefinition = context.chartDefinition;
85
+ var service = context.service;
86
+ var dimensions = {};
87
+
88
+ var dimCount = chartDefinition.dimensions.length;
89
+ while (dimCount--) {
90
+ var dim = chartDefinition.dimensions[dimCount];
91
+ var multiplier = 1;
92
+ var divisor = 1;
93
+ if (stiebeleltron.isDefined(dim.multiplier)) multiplier = dim.multiplier;
94
+ if (stiebeleltron.isDefined(dim.divisor)) divisor = dim.divisor;
95
+ var dimId = this.getDimensionId(context, dim);
96
+ dimensions[dimId] = this.createBasicDimension(dimId, dim.name, multiplier, divisor);
97
}
98
99
chart = {
107
- id: chartId, // the unique id of the chart
108
- name: '', // the unique name of the chart
109
- title: service.name + " " + chartDefinition.title, // the title of the chart
110
- units: chartDefinition.unit, // the units of the chart dimensions
111
- family: 'Inverters', // the family of the chart
112
- context: 'stiebeleltron.inverter', // the context of the chart
113
- type: netdata.chartTypes.stacked, // the type of the chart
114
- priority: stiebeleltron.base_priority + 5, // the priority relative to others in the same family
100
+ id: chartId,
101
+ name: '',
102
+ title: chartDefinition.title,
103
+ units: chartDefinition.unit,
104
+ family: context.category.name,
105
+ context: 'stiebeleltron.' + context.category.id,
106
+ type: chartDefinition.type,
107
+ priority: stiebeleltron.base_priority + chartDefinition.prio,// the priority relative to others in the same family
108
update_every: service.update_every, // the expected update frequency of the chart
116
- dimensions: dim
109
+ dimensions: dimensions
110
};
111
chart = service.chart(chartId, chart);
112
stiebeleltron.charts[chartId] = chart;
@@ -121,25 +114,37 @@ var stiebeleltron = {
114
return chart;
115
},
116
124
- processDimension(dimension, context) {
125
- var value = stiebeleltron.parseRegex(dimension.regex, context.html);
126
- context.service.set(dimension.name, Math.round(value));
117
+ getChartId: function (context) {
118
+ return "stiebeleltron_" + context.page.id +
119
+ "." + context.category.id +
120
+ "." + context.chartDefinition.id;
121
+ },
122
+
123
+ getDimensionId: function (context, dimension) {
124
+ return this.getChartId(context) + "." + dimension.id;
125
},
126
129
- parseRegex(regex, html) {
127
+ processDimension: function (dimension, context) {
128
+ var value = stiebeleltron.parseRegex(dimension.regex, context.html);
129
+ netdata.debug(dimension.name + " : " + value);
130
+ context.service.set(stiebeleltron.getDimensionId(context, dimension), value);
131
+ },
132
133
+ parseRegex: function (regex, html) {
134
+ var match = new RegExp(regex).exec(html);
135
+ return match[1].replace(",", ".");
136
},
137
138
// module.serviceExecute()
139
// this function is called only from this module
140
// its purpose is to prepare the request and call
141
// netdata.serviceExecute()
137
- serviceExecute(name, uri, update_every) {
142
+ serviceExecute: function (name, uri, update_every) {
143
netdata.debug(this.name + ': ' + name + ': url: ' + uri + ', update_every: ' + update_every);
144
145
var service = netdata.service({
146
name: name,
142
- request: netdata.requestFromURL('http://' + uri),
147
+ request: netdata.requestFromURL(uri),
148
update_every: update_every,
149
module: this
150
});
@@ -148,7 +153,7 @@ var stiebeleltron = {
153
},
154
155
151
- configure(config) {
156
+ configure: function (config) {
157
if (stiebeleltron.isUndefined(config.pages)) return 0;
158
var added = 0;
159
var pageCount = config.pages.length;
@@ -160,7 +165,7 @@ var stiebeleltron = {
165
return 0;
166
}
167
if (stiebeleltron.isUndefined(page.update_every)) page.update_every = this.update_every;
163
- this.pages[page.id] = page;
168
+ this.pages[page.name] = page;
169
this.serviceExecute(page.name, page.url, page.update_every);
170
added++;
171
}
@@ -170,20 +175,20 @@ var stiebeleltron = {
175
// module.update()
176
// this is called repeatedly to collect data, by calling
177
// netdata.serviceExecute()
173
- update(service, callback) {
178
+ update: function (service, callback) {
179
service.execute(function (serv, data) {
180
service.module.processResponse(serv, data);
181
callback();
182
});
183
},
184
180
- isUndefined(value) {
185
+ isUndefined: function (value) {
186
return typeof value === 'undefined';
187
},
188
184
- isDefined(value) {
189
+ isDefined: function (value) {
190
return typeof value !== 'undefined';
186
- },
191
+ }
192
};
193
194
module.exports = stiebeleltron;
web/dashboard_info.js
+17
-1
@@ -291,6 +291,12 @@ netdataDashboard.menu = {
291
info: undefined
292
},
293
294
+ 'stiebeleltron': {
295
+ title: 'Stiebel Eltron',
296
+ icon: '<i class="fa fa-thermometer-full" aria-hidden="true"></i>',
297
+ info: undefined
298
+ },
299
+
300
'snmp': {
301
title: 'SNMP',
302
icon: '<i class="fa fa-random" aria-hidden="true"></i>',
@@ -1353,5 +1359,15 @@ netdataDashboard.context = {
1359
commonMin: true,
1360
commonMax: true,
1361
valueRange: "[0, null]"
1356
- }
1362
+ },
1363
+
1364
+ // ------------------------------------------------------------------------
1365
+ // Stiebel Eltron Heat pump installation
1366
+
1367
+ 'stiebeleltron.system.roomtemp': {
1368
+ commonMin: true,
1369
+ commonMax: true,
1370
+ valueRange: "[0, 50]"
1371
+ },
1372
+
1373
};