From ed003c123fdc7c848565d057af8bdc8097ab8e2e Mon Sep 17 00:00:00 2001 From: enkore Date: Sun, 24 Feb 2013 00:34:16 +0100 Subject: [PATCH] temp module --- README.md | 13 ++++++++++++ i3pystatus/__init__.py | 3 +++ i3pystatus/temp.py | 48 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 i3pystatus/temp.py diff --git a/README.md b/README.md index 7b069e0..8e77eda 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,19 @@ Simple regex file watcher +### temp + + +Shows CPU temperature + + +* format — format string used for output. {temp} is the temperature in degrees celsius, {critical} and {high} are the trip point temps. (default: {temp} °C) +* color — (default: #FFFFFF) +* color_critical — (default: #FF0000) +* high_factor — (default: 0.7) + + + ## Contribute diff --git a/i3pystatus/__init__.py b/i3pystatus/__init__.py index 41b4a90..92f783f 100644 --- a/i3pystatus/__init__.py +++ b/i3pystatus/__init__.py @@ -321,6 +321,9 @@ class i3pystatus: def register(self, module, position=0, *args, **kwargs): """Register a new module.""" + if not module: # One can pass in False or None, if he wishes to temporarily disable a module + return + module, position = self.get_instance_for_module(module, position, args, kwargs) self.modules.append(module) diff --git a/i3pystatus/temp.py b/i3pystatus/temp.py new file mode 100644 index 0000000..25edd18 --- /dev/null +++ b/i3pystatus/temp.py @@ -0,0 +1,48 @@ +import re +import glob + +from i3pystatus import IntervalModule + +class Temperature(IntervalModule): + """ + Shows CPU temperature + """ + + settings = ( + ("format", "format string used for output. {temp} is the temperature in degrees celsius, {critical} and {high} are the trip point temps."), + "color", "color_critical", "high_factor" + ) + format = "{temp} °C" + high_factor = 0.7 + color = "#FFFFFF" + color_high = "#FFFF00" + color_critical = "#FF0000" + + def init(self): + self.base_path = "/sys/devices/platform/coretemp.0" + input = glob.glob("{base_path}/temp*_input".format(base_path=self.base_path))[0] + self.input = re.search("temp([0-9]+)_input", input).group(1) + self.base_path = "{base_path}/temp{input}_".format(base_path=self.base_path, input=self.input) + + with open("{base_path}crit".format(base_path=self.base_path), "r") as f: + self.critical = float(f.read().strip()) / 1000 + self.high = self.critical * self.high_factor + + def run(self): + with open("{base_path}input".format(base_path=self.base_path), "r") as f: + temp = float(f.read().strip()) / 1000 + + urgent = False + color = self.color + if temp >= self.critical: + urgent = True + color = self.color_critical + elif temp >= self.high: + urgent = True + color = self.color_high + + self.output = { + "full_text" : self.format.format(temp=temp, critical=self.critical, high=self.high), + "urgent": urgent, + "color": color, + }