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

return baseclass.extend({
	title: _('Thermal Plugin Configuration'),
	description: _('The thermal plugin will monitor temperature of the system. Data is typically read from /sys/class/thermal/*/temp ( \'*\' denotes the thermal device to be read, e.g. thermal_zone1 )'),

	addFormOptions(s) {
		let o;

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

		o = s.option(form.DynamicList, 'Device', _('Monitor device(s) / thermal zone(s)'), _('Empty value = monitor all'));
		o.load = function(section_id) {
			return Promise.all([
				L.resolveDefault(fs.list('/sys/class/thermal'), []),
				L.resolveDefault(fs.list('/proc/acpi/thermal_zone'), [])
			]).then(L.bind(function([therm, therm_zone]) {
				const entries = therm.concat(therm_zone);

				for (let e of entries)
					if (e.type == 'directory' && !e.name.match(/^cooling_device/))
						o.value(e.name);

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

		o.optional = true;
		o.depends('enable', '1');

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

	configSummary(section) {
		const zones = L.toArray(section.Device);
		const invert = section.IgnoreSelected == '1';

		if (zones.length)
			return (invert
				? _('Monitoring all thermal zones except %s')
				: _('Monitoring thermal zones %s')
			).format(zones.join(', '));
		else
			return _('Monitoring all thermal zones');
	}
});