Add average CPU temp to i3status

This commit is contained in:
Dan Buch 2018-10-11 15:49:10 -04:00
parent 999ca0b213
commit e82297530d
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python
import sys
import json
import subprocess
import sys
_BITS = []
@ -44,6 +45,43 @@ def _backlight(dev_dir='/sys/class/backlight/intel_backlight'):
color = '#5599ff'
return '☼:{}%'.format(pct), color
@_bit(7)
def _cputemp():
sensors_job = subprocess.run(
['sensors', '-j'],
check=True, capture_output=True, text=True
)
parsed = json.loads(sensors_job.stdout)
found_core_temps = []
for key, value in parsed.items():
if 'coretemp' not in key:
continue
if not hasattr(value, 'items'):
continue
for subkey, subvalue in value.items():
if 'Core' not in subkey:
continue
if not hasattr(subvalue, 'items'):
continue
for subsubkey, subsubvalue in subvalue.items():
if not subsubkey.endswith('_input'):
continue
found_core_temps.append(subsubvalue)
avg_temp = float(sum(found_core_temps)) / len(found_core_temps)
color = None
if avg_temp > 75:
color = '#ff0000'
if avg_temp >= 50:
color = '#ffaa00'
if avg_temp <= 25:
color = '#5599ff'
return 'T:{}°C'.format(avg_temp), color
def _print_line(message):
sys.stdout.write(message + '\n')