summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-statistics/htdocs/luci-static/resources/view/statistics/plugins/sensors.js
blob: 149e82af074d8a5f4838b5fd696628b2019566fe (plain)
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
'use strict';
'require baseclass';
'require fs';
'require form';

var sensorTypes = [
	/^[0-9]+(?:\.[0-9]+)?v$/,									'voltage',
	/^(?: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',
	/^(?:curr)[0-9]*$/,											'current',
	/^(?:power)[0-9]*$/,										'power'
];

return baseclass.extend({
	title: _('Sensors Plugin Configuration'),
	description: _('The sensors plugin uses the Linux Sensors framework to gather environmental statistics.'),

	addFormOptions(s) {
		let o;

		o = s.option(form.Flag, 'enable', _('Enable this plugin'));

		o = s.option(form.DynamicList, 'Sensor', _('Sensor list'));
		o.rmempty = true;
		o.size = 18;
		o.depends('enable', '1');
		o.load = function(section_id) {
			return fs.exec_direct('/usr/sbin/sensors', ['-j'], 'json').then(L.bind(function(output) {
				for (let bus in output) {
					for (let sensor in output[bus]) {
						if (!L.isObject(output[bus][sensor]))
							continue;

						for (let j = 0; j < sensorTypes.length; j += 2) {
							if (sensor.match(sensorTypes[j])) {
								this.value('%s/%s-%s'.format(bus, sensorTypes[j + 1], sensor));
								break;
							}
						}
					}
				}

				return this.super('load', [section_id]);
			}, this));
		};

		o = s.option(form.Flag, 'IgnoreSelected', _('Monitor all except specified'));
		o.depends('enable', '1');
	},

	configSummary(section) {
		const sensors = L.toArray(section.Sensor);
		const invert = section.IgnoreSelected == '1';

		if (invert && sensors.length)
			return N_(sensors.length, 'Monitoring all but one sensor', 'Monitoring all but %d sensors').format(sensors.length);
		else if (sensors.length)
			return N_(sensors.length, 'Monitoring one sensor', 'Monitoring %d sensors').format(sensors.length);
		else
			return _('Monitoring all sensors');
	}
});