Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved temperature reader #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions pyspectator/temperature_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ class LinuxCpuTemperatureReader():
files = [
'/sys/devices/LNXSYSTM:00/LNXTHERM:00/LNXTHERM:01/thermal_zone/temp',
'/sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/temp',
'/sys/class/thermal/thermal_zone0/temp',
'/proc/acpi/thermal_zone/THM0/temperature',
'/proc/acpi/thermal_zone/THRM/temperature',
'/proc/acpi/thermal_zone/THR1/temperature'

]

@classmethod
def get_reader(cls):
readers = {
cls.files[0]: cls.reader1,
cls.files[1]: cls.reader1,
cls.files[2]: cls.reader2,
cls.files[2]: cls.reader1,
cls.files[3]: cls.reader2,
cls.files[4]: cls.reader2
cls.files[4]: cls.reader2,
cls.files[5]: cls.reader2
}
for file in cls.files:
if path.exists(file):
Expand All @@ -29,8 +32,8 @@ def get_reader(cls):
@classmethod
def reader1(cls, file):
def reader(file):
temperature = open(file).read().strip()
temperature = int(temperature) // 1000
temperature = float(open(file).read().strip())
temperature = temperature / 1000
return temperature
return partial(reader, file)

Expand All @@ -39,7 +42,7 @@ def reader2(cls, file):
def reader(file):
temperature = open(file).read().strip()
temperature = temperature.lstrip('temperature :').rstrip(' C')
return int(temperature)
return float(temperature)
return partial(reader, file)


Expand All @@ -54,7 +57,7 @@ def temperature_reader():
pythoncom.CoInitialize()
w = wmi.WMI(namespace='root\\wmi')
temperature = w.MSAcpi_ThermalZoneTemperature()[0]
temperature = int(temperature.CurrentTemperature / 10.0 - 273.15)
temperature = float(temperature.CurrentTemperature / 10.0 - 273.15)
return temperature
return temperature_reader

Expand Down