From b64b87943b2e1d5955db90a94de611bf2c4bad2a Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Tue, 24 Jan 2017 17:40:51 +0100 Subject: #371: temperatures: change returned data type from list to dict --- psutil/_pslinux.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'psutil/_pslinux.py') diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 28e4a77c..bb3d171b 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -7,6 +7,7 @@ from __future__ import division import base64 +import collections import errno import functools import glob @@ -1096,7 +1097,8 @@ def boot_time(): if os.path.exists('/sys/class/hwmon'): - def sensors_temps(): + + def sensors_temperatures(): """Return hardware (CPU and others) temperatures as a list of named tuples including name, label, current, max and critical temperatures. @@ -1121,22 +1123,23 @@ if os.path.exists('/sys/class/hwmon'): with f: return f.read().strip() - ret = [] + ret = collections.defaultdict(list) basenames = sorted(set( [x.split('_')[0] for x in glob.glob('/sys/class/hwmon/hwmon*/temp*_*')])) for base in basenames: name = cat(os.path.join(os.path.dirname(base), 'name')) label = cat(base + '_label', replace='') - current = int(cat(base + '_input')) / 1000.0 + current = float(cat(base + '_input')) / 1000.0 high = cat(base + '_max', replace=None) critical = cat(base + '_crit', replace=None) + if high is not None: - high = int(high) / 1000.0 + high = float(high) / 1000.0 if critical is not None: - critical = int(critical) / 1000.0 + critical = float(critical) / 1000.0 - ret.append((name, label, current, high, critical)) + ret[name].append((label, current, high, critical)) return ret -- cgit v1.2.1