moniteur/modules/sensors.py

58 lines
1.9 KiB
Python

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from curses import color_pair as get_pair
def sensors_value (sensor):
'''
Returns the float value given by the sensor
To get the sensor's name, start the sensors executable
Warning, this function matches the first sensor named like that, hope that the good one
'''
from os import popen
from re import findall
sensors = popen ('sensors')
data = ''
for i in sensors:
data += i
sensors_line = findall (sensor + '.*', data) [0]
value = findall ('[0-9][0-9\.]+', sensors_line) [0]
#value = findall ('[0-9]*', findall (':[ +]*[0-9]*', sensors_line) [0]) [0]
return (float (value))
def main (line, screen):
screen.addstr (line, 0, '-->', get_pair (5))
screen.addstr (line, 3, 'Températures carte mère :', get_pair (1))
line += 1
cpu = sensors_value ('CPU Temperature')
cpu_fan = sensors_value ('CPU FAN Speed')
mb = sensors_value ('MB Temperature')
power = sensors_value ('POWER FAN Speed')
screen.addstr (line, 0, 'CPU:', get_pair (2))
if cpu < 60:
screen.addstr (line, 5, '%2.0f'%cpu, get_pair (3))
else:
screen.addstr (line, 5, '%2.0f'%cpu, get_pair (4))
screen.addstr (line, 8, '°C', get_pair (1))
screen.addstr (line, 12, 'MB:', get_pair (2))
if mb < 45:
screen.addstr (line, 16, '%2.0f'%mb, get_pair (3))
else:
screen.addstr (line, 16, '%2.0f'%mb, get_pair (4))
screen.addstr (line, 19, '°C', get_pair (1))
screen.addstr (line, 23, 'CPU fan:', get_pair (2))
if cpu_fan < 7200 and cpu_fan > 800:
screen.addstr (line, 32, '%4.0f'%cpu_fan, get_pair (3))
else:
screen.addstr (line, 32, '%4.0f'%cpu_fan, get_pair (4))
screen.addstr (line, 37, 'RPM', get_pair (1))
screen.addstr (line, 41, 'POWER fan:', get_pair (2))
if power < 7200 and power > 1800:
screen.addstr (line, 52, '%4.0f'%power, get_pair (3))
else:
screen.addstr (line, 52, '%4.0f'%power, get_pair (4))
screen.addstr (line, 57, 'RPM', get_pair (1))
line += 1
return (line)