luci-app-statistics: Generate graphs for humidity sensors
authorUwe Kleine-König <uwe@kleine-koenig.org>
Fri, 16 Dec 2022 22:22:04 +0000 (23:22 +0100)
committerUwe Kleine-König <uwe@kleine-koenig.org>
Tue, 10 Jan 2023 14:02:11 +0000 (15:02 +0100)
This fixes graph generation for sensors that provide humidity data.

Suggested-by: Jo-Philipp Wich <jo@mein.io>
Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
applications/luci-app-statistics/htdocs/luci-static/resources/statistics/rrdtool/definitions/sensors.js
applications/luci-app-statistics/htdocs/luci-static/resources/view/statistics/plugins/sensors.js

index b3361e1bf4e777fb5ccbddcd5f9dc98c3c48ebe6..3da1bcfd820052494009a8570c181285fe1b4d60 100644 (file)
@@ -7,20 +7,44 @@ return baseclass.extend({
        title: _('Sensors'),
 
        rrdargs: function(graph, host, plugin, plugin_instance, dtype) {
-               return {
-                       per_instance: true,
-                       title: "%H: %pi - %di",
-                       vlabel: "\xb0C",
-                       number_format: "%4.1lf\xb0C",
-                       data: {
-                               types: [ "temperature" ],
-                               options: {
-                                       temperature__value: {
-                                               color: "ff0000",
-                                               title: "Temperature"
+               var rv = [];
+               var types = graph.dataTypes(host, plugin, plugin_instance);
+
+               if (types.indexOf('temperature') > -1) {
+                       rv.push({
+                               per_instance: true,
+                               title: "%H: %pi - %di",
+                               vlabel: "\xb0C",
+                               number_format: "%4.1lf\xb0C",
+                               data: {
+                                       types: [ "temperature" ],
+                                       options: {
+                                               temperature__value: {
+                                                       color: "ff0000",
+                                                       title: "Temperature"
+                                               }
+                                       }
+                               }
+                       });
+               }
+               if (types.indexOf('humidity') > -1) {
+                       rv.push({
+                               per_instance: true,
+                               title: "%H: %pi - %di",
+                               vlabel: "%RH",
+                               number_format: "%4.1lf %%RH",
+                               data: {
+                                       types: [ "humidity" ],
+                                       options: {
+                                               humidity__value: {
+                                                       color: "0000ff",
+                                                       title: "Humidity"
+                                               }
                                        }
                                }
-                       }
-               };
+                       });
+               }
+
+               return rv;
        }
 });
index 8424966d2d30c6744069ac8cc6eb6b7f9c081bfc..a1a24726542e65c068d9742509bab44a4d6bd6bf 100644 (file)
@@ -8,6 +8,7 @@ var sensorTypes = [
        /^(?:ain|in|vccp|vdd|vid|vin|volt|voltbatt|vrm)[0-9]*$/,        'voltage',
        /^(?:cpu_temp|remote_temp|temp)[0-9]*$/,                                        'temperature',
        /^(?:fan)[0-9]*$/,                                                                                      'fanspeed',
+       /^(?:humidity)[0-9]*$/,                                                                         'humidity',
        /^(?:power)[0-9]*$/,                                                                            'power'
 ];