i3pystatus/i3pystatus/temp.py
David Wahlstrom b901cec5a6 temp: add a "display_if" setting
Adds a "display_if" setting to temp module.  This is a snippet that will
be evaulated, and if the result is true, it will display the module's
output.
2016-05-11 13:38:28 -07:00

36 lines
1.0 KiB
Python

from i3pystatus import IntervalModule
class Temperature(IntervalModule):
"""
Shows CPU temperature of Intel processors
AMD is currently not supported as they can only report a relative temperature, which is pretty useless
"""
settings = (
("format",
"format string used for output. {temp} is the temperature in degrees celsius"),
('display_if', 'snippet that gets evaluated. if true, displays the module output'),
"color",
"file",
"alert_temp",
"alert_color",
)
format = "{temp} °C"
color = "#FFFFFF"
file = "/sys/class/thermal/thermal_zone0/temp"
alert_temp = 90
alert_color = "#FF0000"
display_if = 'True'
def run(self):
with open(self.file, "r") as f:
temp = float(f.read().strip()) / 1000
if eval(self.display_if):
self.output = {
"full_text": self.format.format(temp=temp),
"color": self.color if temp < self.alert_temp else self.alert_color,
}