Use same temperature sources as thinkfan if available
This commit is contained in:
parent
e82297530d
commit
0354e8e441
42
i3wrapper.py
42
i3wrapper.py
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -45,33 +46,25 @@ def _backlight(dev_dir='/sys/class/backlight/intel_backlight'):
|
|||||||
color = '#5599ff'
|
color = '#5599ff'
|
||||||
return '☼:{}%'.format(pct), color
|
return '☼:{}%'.format(pct), color
|
||||||
|
|
||||||
|
|
||||||
|
THINKFAN_CONF = '/etc/thinkfan.conf'
|
||||||
|
|
||||||
|
|
||||||
@_bit(7)
|
@_bit(7)
|
||||||
def _cputemp():
|
def _hwtemp(conf=THINKFAN_CONF):
|
||||||
sensors_job = subprocess.run(
|
if not os.path.exists(THINKFAN_CONF):
|
||||||
['sensors', '-j'],
|
return None, None
|
||||||
check=True, capture_output=True, text=True
|
|
||||||
)
|
|
||||||
parsed = json.loads(sensors_job.stdout)
|
|
||||||
found_core_temps = []
|
|
||||||
|
|
||||||
for key, value in parsed.items():
|
temps = []
|
||||||
if 'coretemp' not in key:
|
|
||||||
continue
|
|
||||||
if not hasattr(value, 'items'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
for subkey, subvalue in value.items():
|
with open('/etc/thinkfan.conf') as tfc_fp:
|
||||||
if 'Core' not in subkey:
|
for line in tfc_fp.readlines():
|
||||||
continue
|
if not line.startswith('hwmon '):
|
||||||
if not hasattr(subvalue, 'items'):
|
|
||||||
continue
|
continue
|
||||||
|
with open(line.split(' ')[1].strip()) as temp_fp:
|
||||||
|
temps.append(float(temp_fp.read()))
|
||||||
|
|
||||||
for subsubkey, subsubvalue in subvalue.items():
|
avg_temp = float(sum(temps)) / len(temps) / 1000.0
|
||||||
if not subsubkey.endswith('_input'):
|
|
||||||
continue
|
|
||||||
found_core_temps.append(subsubvalue)
|
|
||||||
|
|
||||||
avg_temp = float(sum(found_core_temps)) / len(found_core_temps)
|
|
||||||
color = None
|
color = None
|
||||||
|
|
||||||
if avg_temp > 75:
|
if avg_temp > 75:
|
||||||
@ -80,7 +73,7 @@ def _cputemp():
|
|||||||
color = '#ffaa00'
|
color = '#ffaa00'
|
||||||
if avg_temp <= 25:
|
if avg_temp <= 25:
|
||||||
color = '#5599ff'
|
color = '#5599ff'
|
||||||
return 'T:{}°C'.format(avg_temp), color
|
return 'T:{:.1f}°C'.format(avg_temp), color
|
||||||
|
|
||||||
|
|
||||||
def _print_line(message):
|
def _print_line(message):
|
||||||
@ -110,6 +103,9 @@ def main(bits=_BITS):
|
|||||||
loaded = json.loads(line)
|
loaded = json.loads(line)
|
||||||
for idx, name, func in bits:
|
for idx, name, func in bits:
|
||||||
value, color = func()
|
value, color = func()
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
|
|
||||||
record = dict(full_text=str(value), name=name)
|
record = dict(full_text=str(value), name=name)
|
||||||
if color is not None:
|
if color is not None:
|
||||||
record.update(dict(color=color))
|
record.update(dict(color=color))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user