lmsensors 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/FMAPPER.md +20 -0
- data/LICENSE.txt +165 -0
- data/README.md +156 -0
- data/ext/lmsensors_base/extconf.rb +9 -0
- data/lib/lmsensors.rb +13 -0
- data/lib/lmsensors/feature.rb +11 -0
- data/lib/lmsensors/features/abs_feature.rb +85 -0
- data/lib/lmsensors/features/alarm.rb +38 -0
- data/lib/lmsensors/features/beep.rb +33 -0
- data/lib/lmsensors/features/current.rb +69 -0
- data/lib/lmsensors/features/fan.rb +52 -0
- data/lib/lmsensors/features/humidity.rb +35 -0
- data/lib/lmsensors/features/power.rb +80 -0
- data/lib/lmsensors/features/temp.rb +69 -0
- data/lib/lmsensors/features/voltage.rb +69 -0
- data/lib/lmsensors/lm_constants.rb +193 -0
- data/lib/lmsensors/lmsensors.rb +33 -0
- data/lib/lmsensors/sensors/abssensor.rb +151 -0
- data/lib/lmsensors/sensors/sensor.rb +148 -0
- data/lib/lmsensors/sensors/sensorspawner.rb +77 -0
- data/lib/lmsensors/version.rb +8 -0
- data/lib/lmsensors_base/lmsensors_base.so +0 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e6e1c703203fcebc6433c02baeb8e27d25cdc94acd25937c1a22291fec0b7031
|
4
|
+
data.tar.gz: 8cb6984cff4359a059566c16f4c7674cf170a9a4564ccc848922da6825b64692
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c90e178a106a429a89f887c960568424af6860a834b441dc3292ca5225fa775a42d25d78a8cf7c5f9b4bbe18fe02af35843bfaa636d4326a22631660bd77eb84
|
7
|
+
data.tar.gz: 63a5335b4c7c4814162591921771935b6c17f4bdb5dbb699375f693cff88a622734b5f71084380432d0c95db1fd563878b3513fa56c921e7d8582638295c2b14
|
data/CHANGELOG.md
ADDED
data/FMAPPER.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
### FMAPPER INFORMATION ###
|
2
|
+
|
3
|
+
For the default implementation, you should view ``lib/lmsensors/lm_constants.rb``.
|
4
|
+
|
5
|
+
I have included a default feature mapper for most common sensor types, largely to mimic what is included in the ``sensors`` CLI program's formatter. If it is insufficient, however, then you can feel free to use your own.
|
6
|
+
|
7
|
+
Unless heavily overriding the classes, the mapper should have an arity of 2 (name of the object, object data). I will not go into details about how to create complex format maps or heavily override the classes. However, the ``AbsFeature`` and all subclasses take the name of the feature (a symbol, such as ``:temp1``) and the feature's data, which includes all of its subfeatures.
|
8
|
+
|
9
|
+
The default mapper, however, simply generates a ``Feature::GenFeature.new(name, f_obj)`` for a case statement, based on the feature's type (``SF_FAN``, ``SF_TEMP``, ``SF_VOLTAGE``, etc.). If you create an alternative, it should do similar.
|
10
|
+
```ruby
|
11
|
+
case f_obj[:type]
|
12
|
+
when []
|
13
|
+
...
|
14
|
+
when []
|
15
|
+
...
|
16
|
+
else
|
17
|
+
...
|
18
|
+
end
|
19
|
+
```
|
20
|
+
For all intents and purposes, your own format-mapper can have a single clause, if you don't care about anything else. All of the ``AbsFeature`` subclasses were purely for convenience, and they should provide for the vast majority of use cases.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README.md
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
### OVERVIEW ###
|
2
|
+
LmSensors is a C-Ruby API wrapper for ``lmsensors`` (which runs the ``sensors`` and ``sensors-detect`` commands) on Linux systems. This will allow users to access temperature, fan, and bus data for various system hardware devices.
|
3
|
+
|
4
|
+
### USAGE ###
|
5
|
+
```ruby
|
6
|
+
# Global value only relevant to overriding format-mapping
|
7
|
+
# functions. This is 'false', by default, but when set to
|
8
|
+
# 'true', it disables a warning about the arity passed to
|
9
|
+
# the format-mapping method of the abstract GenSensor, as
|
10
|
+
# this class cannot guarantee knowing subclasses.
|
11
|
+
$LmSensorsIgnArity
|
12
|
+
|
13
|
+
LmSensors.init # Initialize the Sensors system data
|
14
|
+
LmSensors.cleanup # Cleanup the Sensors data, when done
|
15
|
+
|
16
|
+
# Create a new sensor spawner/bag
|
17
|
+
# ``.enum`` and ``.stat`` default to ALL sensors, unless
|
18
|
+
# a name is set with ``.set_name``
|
19
|
+
s = LmSensors::SensorSpawner.new
|
20
|
+
# LmSensors::Sensors is now just an alias of SensorSpawner.
|
21
|
+
# I left this for compatibility purposes.
|
22
|
+
|
23
|
+
# Count the number of sensors detected by the spawner,
|
24
|
+
# with the current settings. Also works with a concrete
|
25
|
+
# Sensor object, but will return the number of features.
|
26
|
+
s.count # or s.count_s
|
27
|
+
|
28
|
+
# Locate a specific Sensor on a SensorSpawner. This is
|
29
|
+
# a shorthand way to assign a specific sensor, quickly, if you
|
30
|
+
# already know the path, such as what might have been returned
|
31
|
+
# from another gem or script.
|
32
|
+
s.locate :path # Where path is something like '/sys/class/hwmon/hwmon3'
|
33
|
+
|
34
|
+
# Assign a list of all the selected sensors available
|
35
|
+
# ``.enum`` will return a list of LmSensors::AbsSensor objects
|
36
|
+
# or their subclasses.
|
37
|
+
items = s.enum
|
38
|
+
|
39
|
+
# Sets the fmap of the sensor. If this is set on a SensorSpawner,
|
40
|
+
# it will automatically use the same format map for any sensors it
|
41
|
+
# creates. If it is set on a single Sensor, it will only affect that
|
42
|
+
# one. This method can be used to pass in a custom Proc/Lambda
|
43
|
+
# object for the sensor in question to use as its feature-formatting
|
44
|
+
# selector. By default, the format will be 'LmSensors::DEF_FMAP'.
|
45
|
+
#
|
46
|
+
# For more details on this, please view 'FMAPPER.md'
|
47
|
+
s.set_fmap :your_proc
|
48
|
+
|
49
|
+
s.reset_fmap # Reset it back to the default
|
50
|
+
|
51
|
+
# Where :idx is an int in range, assign new
|
52
|
+
# Sensor object to sobj.
|
53
|
+
sobj = items[:idx]
|
54
|
+
sobj.name # Name of Sensor
|
55
|
+
sobj.adapater # Adapter of Sensor
|
56
|
+
sobj.path # Path of Sensor
|
57
|
+
sobj.info # Return the name, adapter, and path of a Sensor
|
58
|
+
sobj.read # Raw data from the :stat part of the Sensor
|
59
|
+
sobj.stat # Stat the selected sensor, returning features
|
60
|
+
sobj.features # Alias for :stat
|
61
|
+
sobj.count # Count the number of features
|
62
|
+
sobj.count_s # Alias for :count
|
63
|
+
sobj.count_sf # Return the number of subfeatures on a Sensor object
|
64
|
+
|
65
|
+
# Set the name of the desired sensors to collect
|
66
|
+
# Can be set to either specific sensor or a wildcard.
|
67
|
+
#
|
68
|
+
# This will return a list of AbsSensors of the type.
|
69
|
+
#
|
70
|
+
# Example: "amdgpu-*", for ANY Radeon card using this driver
|
71
|
+
# Example: "*-pci-*", for ANY device on the PCI bus
|
72
|
+
# Example: "k10temp-pci-00c3", for a Ryzen or other k10temp CPU
|
73
|
+
# identified on the PCI bus, with the identifier, '00c3'
|
74
|
+
# (This is from my dev system, so yours might be different)
|
75
|
+
s.set_name :name
|
76
|
+
s.name # Return the current chip or collector's name
|
77
|
+
s.unset_name # Unset the chip selection -- ``.enum`` will go back to ALL chips
|
78
|
+
|
79
|
+
# Set the filters to return for a Sensor.
|
80
|
+
# The selected features must be an array.
|
81
|
+
# For convenience, the features may use the
|
82
|
+
# constants from the class.
|
83
|
+
#
|
84
|
+
# Example: [1,2], for ONLY fans and temps
|
85
|
+
# Example: [LmSensors::SF_FAN, LmSensors::SF_POWER], for ONLY fans and power
|
86
|
+
sobj.set_filters :arr_of_choices
|
87
|
+
sobj.unset_filters # Unset the filters -- returns ALL
|
88
|
+
|
89
|
+
# Toggle whether to receive the subfeatures or
|
90
|
+
# only to receive the features with their type.
|
91
|
+
# By default, this is false, and you will receive the
|
92
|
+
# type only.
|
93
|
+
sobj.toggle_subs
|
94
|
+
|
95
|
+
# Toggle whether to format output. By default, this is false.
|
96
|
+
# When false, it returns the raw state of the feature object.
|
97
|
+
sobj.toggle_fmt
|
98
|
+
|
99
|
+
# Assign the features from a Sensor.
|
100
|
+
# This will return an array of Feature objects.
|
101
|
+
fs = sobj.features # This is an alias for :stat
|
102
|
+
|
103
|
+
# Format the feature data. Some types will have a pre-defined
|
104
|
+
# format, but for others, you can derive LmSensors::Feature::GenFeature.
|
105
|
+
#
|
106
|
+
# This method can also take a separate formatter. The default is
|
107
|
+
# 'LmSensors::Feature::BASE_FMT', which returns it as a simple hash.
|
108
|
+
fs[0].fmt # Will format the first feature returned.
|
109
|
+
|
110
|
+
# This will return the feature type and name.
|
111
|
+
#
|
112
|
+
# Example: { :name => :vddgfx, :type => 0 }, for the voltage on my GPU
|
113
|
+
# :vddgfx is the name
|
114
|
+
# :type => 0, refers to the fact that this feature is measured with
|
115
|
+
# the voltage type (LmSensors::SF_IN, Voltage, 0).
|
116
|
+
fs[0].feature
|
117
|
+
```
|
118
|
+
|
119
|
+
### TO-DO ###
|
120
|
+
~~1) DONE, FINALLY!~~
|
121
|
+
|
122
|
+
### INSTALLATION ###
|
123
|
+
_DEV LIBS: As this is an extension, you will require the Ruby development headers. On some systems, this will come packaged with your Ruby installation. On others, you may need to install additional packages, such as ``ruby-dev`` (Ubuntu and similar). Check your specific system's requirements, and make sure you have the headers, as well as RubyGems and Rdoc_
|
124
|
+
|
125
|
+
This wrapper requires the header files for ``lmsensors`` to be installed. For some systems, it will come with the userspace package directly. For others, it is a separate package. The header required is ``sensors.h``.
|
126
|
+
|
127
|
+
NOTE: Below is how you can install it on various distros. As I use Arch and Debian, I had to look up the others, so if there is an issue, please submit the correction, and I will fix it.
|
128
|
+
|
129
|
+
Arch:
|
130
|
+
```
|
131
|
+
sudo pacman -S lm_sensors
|
132
|
+
```
|
133
|
+
Debian-like (Debian, Ubuntu, Mint):
|
134
|
+
```
|
135
|
+
sudo apt install lm-sensors libsensors-dev
|
136
|
+
```
|
137
|
+
Fedora-like:
|
138
|
+
```
|
139
|
+
sudo yum install lm_sensors lm_sensors-devel
|
140
|
+
sudo dnf install lm_sensors lm_sensors-devel
|
141
|
+
```
|
142
|
+
Gentoo:
|
143
|
+
```
|
144
|
+
sudo emerge --ask sys-apps/lm_sensors
|
145
|
+
```
|
146
|
+
For OpenSUSE, you will need to find a package that provides ``sensors.h``
|
147
|
+
https://www.mankier.com/8/zypper.
|
148
|
+
However, it appears that the correct way to install it will be:
|
149
|
+
```
|
150
|
+
sudo zypper install libsensors4-devel
|
151
|
+
```
|
152
|
+
|
153
|
+
Then, you can install it for Ruby:
|
154
|
+
```
|
155
|
+
gem install lmsensors
|
156
|
+
```
|
data/lib/lmsensors.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# lib/lmsensors.rb
|
2
|
+
|
3
|
+
##
|
4
|
+
# This global is set up, to handle ignoring of
|
5
|
+
# arity of passed procs for feature mapping.
|
6
|
+
$LmSensorsIgnArity = false
|
7
|
+
|
8
|
+
##
|
9
|
+
# This module is a C-Ruby wrapper for
|
10
|
+
# the program ``sensors``, which uses the
|
11
|
+
# library ``lmsensors``, on Linux.
|
12
|
+
require_relative "./lmsensors/lmsensors"
|
13
|
+
require_relative "./lmsensors/version"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# lib/lmsensors/feature.rb
|
2
|
+
|
3
|
+
# Require the extra classes
|
4
|
+
require_relative "./features/voltage"
|
5
|
+
require_relative "./features/current"
|
6
|
+
require_relative "./features/power"
|
7
|
+
require_relative "./features/temp"
|
8
|
+
require_relative "./features/fan"
|
9
|
+
require_relative "./features/humidity"
|
10
|
+
require_relative "./features/alarm"
|
11
|
+
require_relative "./features/beep"
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# lib/lmsensors/features/abs_feature.rb
|
2
|
+
|
3
|
+
# Make sure to include the constants
|
4
|
+
require_relative "../lm_constants"
|
5
|
+
|
6
|
+
# :nodoc: Append to the main module
|
7
|
+
module LmSensors
|
8
|
+
##
|
9
|
+
# Feature module is used to handle the formatting
|
10
|
+
# and inheritance of various feature types.
|
11
|
+
module Feature
|
12
|
+
##
|
13
|
+
# Base formatting for anything else.
|
14
|
+
# This pretty much just converts a general
|
15
|
+
# feature object into a hash, so it can be
|
16
|
+
# indexed in post-processing.
|
17
|
+
BASE_FMT = lambda do |feature|
|
18
|
+
# Attach the main feature name and unit type
|
19
|
+
fstruct = { name: feature.name, type: feature.type, unit: feature.unit }
|
20
|
+
# Merge the subfeatures
|
21
|
+
fstruct.merge(feature.subfs)
|
22
|
+
end # End base formatter proc
|
23
|
+
|
24
|
+
##
|
25
|
+
# The generic GenFeature class is appended to the LmSensors
|
26
|
+
# to handle generic formatting on feature types that
|
27
|
+
# generally will not need additional post-processing.
|
28
|
+
class GenFeature
|
29
|
+
##
|
30
|
+
# GenFeature :default_formatter is BASE_FMT, which returns a
|
31
|
+
# simple representation of the sensor subfeatures, if no
|
32
|
+
# clear formatting can be determined.
|
33
|
+
attr_reader :default_formatter
|
34
|
+
##
|
35
|
+
# GenFeature :name is the name of the feature, such as ':temp1'
|
36
|
+
attr_reader :name
|
37
|
+
##
|
38
|
+
# GenFeature :subfs is a list/array of the subfeatures for this feature
|
39
|
+
attr_reader :subfs
|
40
|
+
##
|
41
|
+
# GenFeature :type is the type of the feature, such as SF_TEMP or SF_FAN
|
42
|
+
attr_reader :type
|
43
|
+
##
|
44
|
+
# GenFeature :unit is the default unit that is likely desired to
|
45
|
+
# represent subfeatures in this feature.
|
46
|
+
# Example: :temp1 may have :temp1_input and :temp1_crit, but both
|
47
|
+
# would be formatted with °C, which is returned from
|
48
|
+
# LmSensors::UNITS[SF_TEMP]
|
49
|
+
attr_reader :unit
|
50
|
+
|
51
|
+
##
|
52
|
+
# Constructor
|
53
|
+
def initialize(name, data)
|
54
|
+
# Attach the default formatter
|
55
|
+
def_fmt
|
56
|
+
# Attach the base data for this instance
|
57
|
+
@name, @type, @subfs = name, data[:type], data
|
58
|
+
@subfs.delete(:type) # Remove :type from the hash (for cleaner iteration)
|
59
|
+
@unit = LmSensors::UNITS[@type] # Units
|
60
|
+
end # End constructor
|
61
|
+
|
62
|
+
##
|
63
|
+
# Return just the feature keys
|
64
|
+
def feature() { name: @name, type: @type, unit: @unit } end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Set the default formatter for the subclass.
|
68
|
+
# If not overridden, will be be the default for
|
69
|
+
# the abstract general class.
|
70
|
+
def def_fmt() @default_formatter = LmSensors::Feature::BASE_FMT end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Format the output struct. This uses
|
74
|
+
# a default formatter, but any desired formatting
|
75
|
+
# function can be passed. The formatter should be
|
76
|
+
# a lambda or proc type.
|
77
|
+
def fmt(callback=@default_formatter)
|
78
|
+
#puts "Abstract formatter for #{self.class}"
|
79
|
+
# If the callback is the wrong type, sue the default
|
80
|
+
cb = Proc === callback ? callback : @default_formatter
|
81
|
+
cb.call(self)
|
82
|
+
end # End formatting of new struct type
|
83
|
+
end # End abstract Feature class
|
84
|
+
end # End Feature module
|
85
|
+
end # End LmSensors inclusion
|