[modules/sensors] Remove sensors dependency and read from device

was having some problems with the current implementation as i have multiple values with the same name in sensors -u.
this way it is unambiguous and *should* just work everywhere with no lm_sensors required, though some distros might move the pseudo file elsewhere, not sure, but thats why it is configurable.
testing would be great.
also, the file is simpler too.
This commit is contained in:
ibrokemypie 2017-07-19 21:40:57 +10:00
parent 14f0af373c
commit 58298d5e30
2 changed files with 5 additions and 16 deletions

View file

@ -119,7 +119,6 @@ Modules and commandline utilities are only required for modules, the core itself
* ping (for the module 'ping') * ping (for the module 'ping')
* redshift (for the module 'redshift') * redshift (for the module 'redshift')
* xrandr (for the module 'xrandr') * xrandr (for the module 'xrandr')
* sensors (for the module 'sensors')
* mpc (for the module 'mpd') * mpc (for the module 'mpd')
* bluez / blueman (for module 'bluetooth') * bluez / blueman (for module 'bluetooth')
* dbus-send (for module 'bluetooth') * dbus-send (for module 'bluetooth')

View file

@ -3,12 +3,8 @@
"""Displays sensor temperature """Displays sensor temperature
Requires the following executable:
* sensors
Parameters: Parameters:
* sensors.match: Line to match against output of 'sensors -u' (default: temp1_input) * sensors.path: path to temperature file (default /sys/class/thermal/thermal_zone0/temp).
* sensors.match_number: which of the matches you want (default -1: last match).
""" """
import re import re
@ -23,19 +19,13 @@ class Module(bumblebee.engine.Module):
bumblebee.output.Widget(full_text=self.temperature)) bumblebee.output.Widget(full_text=self.temperature))
self._temperature = "unknown" self._temperature = "unknown"
self._mhz = "n/a" self._mhz = "n/a"
pattern = self.parameter("match", "temp1_input")
pattern_string = r"^\s*{}:\s*([\d.]+)$".format(pattern)
self._match_number = int(self.parameter("match_number", "-1"))
self._pattern = re.compile(pattern_string, re.MULTILINE)
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd="xsensors") engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd="xsensors")
def get_temp(self): def get_temp(self):
temperatures = bumblebee.util.execute("sensors -u") try:
matching_temp = self._pattern.findall(temperatures) temperature = open(self.parameter("path", "/sys/class/thermal/thermal_zone0/temp")).read()[:2]
except IOError:
temperature = "unknown" temperature = "unknown"
if matching_temp:
temperature = int(float(matching_temp[self._match_number]))
return temperature return temperature
def get_mhz( self ): def get_mhz( self ):