mirror of https://github.com/nicolargo/glances
Fix Celsius to Fahrenheit conversion under Python 3
Exclude battery from conversion too.pull/704/head
parent
3daa17bb23
commit
a9c5adb334
|
@ -118,9 +118,9 @@ class GlancesGrabHDDTemp(object):
|
||||||
hddtemp_current = {}
|
hddtemp_current = {}
|
||||||
device = fields[offset + 1].decode('utf-8')
|
device = fields[offset + 1].decode('utf-8')
|
||||||
device = os.path.basename(device)
|
device = os.path.basename(device)
|
||||||
temperature = fields[offset + 3]
|
temperature = float(fields[offset + 3].decode('utf-8'))
|
||||||
hddtemp_current['label'] = device
|
hddtemp_current['label'] = device
|
||||||
hddtemp_current['value'] = temperature.decode('utf-8')
|
hddtemp_current['value'] = temperature
|
||||||
self.hddtemp_list.append(hddtemp_current)
|
self.hddtemp_list.append(hddtemp_current)
|
||||||
|
|
||||||
def fetch(self):
|
def fetch(self):
|
||||||
|
|
|
@ -45,6 +45,11 @@ else:
|
||||||
SENSOR_FAN_UNIT = 'RPM'
|
SENSOR_FAN_UNIT = 'RPM'
|
||||||
|
|
||||||
|
|
||||||
|
def to_fahrenheit(celsius):
|
||||||
|
"""Convert Celsius to Fahrenheit."""
|
||||||
|
return celsius * 1.8 + 32
|
||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances sensors plugin.
|
"""Glances sensors plugin.
|
||||||
|
@ -202,12 +207,11 @@ class Plugin(GlancesPlugin):
|
||||||
if args.fahrenheit:
|
if args.fahrenheit:
|
||||||
msg = msg.replace('°C', '°F')
|
msg = msg.replace('°C', '°F')
|
||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg))
|
||||||
if args.fahrenheit:
|
if args.fahrenheit and i['type'] != 'battery':
|
||||||
# Convert Celsius to Fahrenheit
|
value = to_fahrenheit(i['value'])
|
||||||
# T(°F) = T(°C) × 1.8 + 32
|
|
||||||
msg = '{0:>7}'.format(i['value'] * 1.8 + 32)
|
|
||||||
else:
|
else:
|
||||||
msg = '{0:>7}'.format(i['value'])
|
value = i['value']
|
||||||
|
msg = '{0:>7.0f}'.format(value)
|
||||||
ret.append(self.curse_add_line(
|
ret.append(self.curse_add_line(
|
||||||
msg, self.get_views(item=i[self.get_key()],
|
msg, self.get_views(item=i[self.get_key()],
|
||||||
key='value',
|
key='value',
|
||||||
|
|
Loading…
Reference in New Issue