Use same temperature sources as thinkfan if available

main
Dan Buch 6 years ago
parent e82297530d
commit 0354e8e441
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

@ -1,5 +1,6 @@
#!/usr/bin/env python
import json
import os
import subprocess
import sys
@ -45,33 +46,25 @@ def _backlight(dev_dir='/sys/class/backlight/intel_backlight'):
color = '#5599ff'
return '☼:{}%'.format(pct), color
THINKFAN_CONF = '/etc/thinkfan.conf'
@_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
def _hwtemp(conf=THINKFAN_CONF):
if not os.path.exists(THINKFAN_CONF):
return None, None
for subsubkey, subsubvalue in subvalue.items():
if not subsubkey.endswith('_input'):
continue
found_core_temps.append(subsubvalue)
temps = []
avg_temp = float(sum(found_core_temps)) / len(found_core_temps)
with open('/etc/thinkfan.conf') as tfc_fp:
for line in tfc_fp.readlines():
if not line.startswith('hwmon '):
continue
with open(line.split(' ')[1].strip()) as temp_fp:
temps.append(float(temp_fp.read()))
avg_temp = float(sum(temps)) / len(temps) / 1000.0
color = None
if avg_temp > 75:
@ -80,7 +73,7 @@ def _cputemp():
color = '#ffaa00'
if avg_temp <= 25:
color = '#5599ff'
return 'T:{}°C'.format(avg_temp), color
return 'T:{:.1f}°C'.format(avg_temp), color
def _print_line(message):
@ -110,6 +103,9 @@ def main(bits=_BITS):
loaded = json.loads(line)
for idx, name, func in bits:
value, color = func()
if value is None:
continue
record = dict(full_text=str(value), name=name)
if color is not None:
record.update(dict(color=color))

Loading…
Cancel
Save