Merge pull request #65 from mijoharas/feature-sensors-module

Feature sensors module
This commit is contained in:
tobi-wan-kenobi 2017-04-19 18:48:10 +02:00 committed by GitHub
commit 870130b8c3
3 changed files with 48 additions and 1 deletions

View file

@ -102,6 +102,7 @@ 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')
# Examples # Examples
Here are some screenshots for all themes that currently exist: Here are some screenshots for all themes that currently exist:

View file

@ -0,0 +1,43 @@
"""Displays sensor temperature
Requires the following executable:
* sensors
Parameters:
* sensors.match: What line in the output of `sensors -u` should be matched against (default: temp1_input)
* sensors.match_number: which of the matches you want (default -1: last match).
"""
import os
import re
import bumblebee.input
import bumblebee.output
import bumblebee.engine
class Module(bumblebee.engine.Module):
def __init__(self, engine, config):
super(Module, self).__init__(engine, config,
bumblebee.output.Widget(full_text=self.temperature)
)
self._temperature = 'unknown'
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")
def get_temp(self):
temperatures = bumblebee.util.execute("sensors -u")
matching_temp = self._pattern.findall(temperatures)
temperature = 'unknown'
if matching_temp:
temperature = matching_temp[self._match_number]
return temperature
def temperature(self, widget):
return self._temperature
def update(self, widgets):
self._temperature = self.get_temp()

View file

@ -75,5 +75,8 @@
}, },
"redshift": { "redshift": {
"day": { "prefix": "" }, "night": { "prefix": "" }, "transition": { "prefix": "" } "day": { "prefix": "" }, "night": { "prefix": "" }, "transition": { "prefix": "" }
},
"sensors": {
"prefix": "🌡"
} }
} }