Fix Celsius to Fahrenheit conversion under Python 3

Exclude battery from conversion too.
pull/704/head
Alessio Sergi 2015-10-11 16:11:10 +02:00
parent 3daa17bb23
commit a9c5adb334
2 changed files with 11 additions and 7 deletions

View File

@ -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):

View File

@ -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',