temp module

This commit is contained in:
enkore 2013-02-24 00:34:16 +01:00
parent a0fc9eb492
commit ed003c123f
3 changed files with 64 additions and 0 deletions

View File

@ -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 ## Contribute

View File

@ -321,6 +321,9 @@ class i3pystatus:
def register(self, module, position=0, *args, **kwargs): def register(self, module, position=0, *args, **kwargs):
"""Register a new module.""" """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) module, position = self.get_instance_for_module(module, position, args, kwargs)
self.modules.append(module) self.modules.append(module)

48
i3pystatus/temp.py Normal file
View File

@ -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,
}