From 3d50024e5ff0a1cf5c02a76967d3dd38e32db893 Mon Sep 17 00:00:00 2001 From: mike-work Date: Wed, 19 Apr 2017 12:36:35 +0100 Subject: [PATCH] Create sensors module. --- bumblebee/modules/sensors.py | 43 +++++++++++++++++++++++++++++++++ themes/icons/awesome-fonts.json | 5 +++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 bumblebee/modules/sensors.py diff --git a/bumblebee/modules/sensors.py b/bumblebee/modules/sensors.py new file mode 100644 index 0000000..ffee663 --- /dev/null +++ b/bumblebee/modules/sensors.py @@ -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() diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 8192217..b3b2867 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -75,5 +75,8 @@ }, "redshift": { "day": { "prefix": "" }, "night": { "prefix": "" }, "transition": { "prefix": "" } - } + }, + "sensors": { + "prefix": "🌡" + } }