提交 a9c5adb3 编写于 作者: A Alessio Sergi

Fix Celsius to Fahrenheit conversion under Python 3

Exclude battery from conversion too.
上级 3daa17bb
......@@ -118,9 +118,9 @@ class GlancesGrabHDDTemp(object):
hddtemp_current = {}
device = fields[offset + 1].decode('utf-8')
device = os.path.basename(device)
temperature = fields[offset + 3]
temperature = float(fields[offset + 3].decode('utf-8'))
hddtemp_current['label'] = device
hddtemp_current['value'] = temperature.decode('utf-8')
hddtemp_current['value'] = temperature
self.hddtemp_list.append(hddtemp_current)
def fetch(self):
......
......@@ -45,6 +45,11 @@ else:
SENSOR_FAN_UNIT = 'RPM'
def to_fahrenheit(celsius):
"""Convert Celsius to Fahrenheit."""
return celsius * 1.8 + 32
class Plugin(GlancesPlugin):
"""Glances sensors plugin.
......@@ -202,12 +207,11 @@ class Plugin(GlancesPlugin):
if args.fahrenheit:
msg = msg.replace('°C', '°F')
ret.append(self.curse_add_line(msg))
if args.fahrenheit:
# Convert Celsius to Fahrenheit
# T(°F) = T(°C) × 1.8 + 32
msg = '{0:>7}'.format(i['value'] * 1.8 + 32)
if args.fahrenheit and i['type'] != 'battery':
value = to_fahrenheit(i['value'])
else:
msg = '{0:>7}'.format(i['value'])
value = i['value']
msg = '{0:>7.0f}'.format(value)
ret.append(self.curse_add_line(
msg, self.get_views(item=i[self.get_key()],
key='value',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册