Crash on launch when viewing temperature of laptop HDD in sleep mode 2/2 (issue #824)

This commit is contained in:
nicolargo 2016-03-28 10:52:53 +02:00
parent e8fda683f1
commit 537baa23dd
2 changed files with 25 additions and 14 deletions

View File

@ -96,6 +96,7 @@ class GlancesGrabHDDTemp(object):
return
# Fetch the data
# data = "|/dev/sda|WDC WD2500JS-75MHB0|44|C||/dev/sdb|WDC WD2500JS-75MHB0|35|C||/dev/sdc|WDC WD3200AAKS-75B3A0|45|C||/dev/sdd|WDC WD3200AAKS-75B3A0|45|C||/dev/sde|WDC WD3200AAKS-75B3A0|43|C||/dev/sdf|SAMSUNG HM321HI|39|C||/dev/sdg|HGST HTS541010A9E680|SLP|*|"
data = self.fetch()
# Exit if no data
@ -120,8 +121,11 @@ class GlancesGrabHDDTemp(object):
temperature = fields[offset + 3]
unit = nativestr(fields[offset + 4])
hddtemp_current['label'] = device
# Temperature could be 'ERR' or 'SLP' (see issue#824)
hddtemp_current['value'] = float(temperature) if isinstance(temperature, numbers.Number) else temperature
try:
hddtemp_current['value'] = float(temperature)
except ValueError:
# Temperature could be 'ERR' or 'SLP' (see issue#824)
hddtemp_current['value'] = temperature
hddtemp_current['unit'] = unit
self.hddtemp_list.append(hddtemp_current)

View File

@ -183,18 +183,25 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg, "TITLE"))
for i in self.stats:
if i['value'] != b'ERR':
# New line
ret.append(self.curse_new_line())
# Alias for the lable name ?
label = self.has_alias(i['label'].lower())
if label is None:
label = i['label']
if i['type'] != 'fan_speed':
msg = '{0:15}'.format(label[:15])
else:
msg = '{0:13}'.format(label[:13])
ret.append(self.curse_add_line(msg))
# New line
ret.append(self.curse_new_line())
# Alias for the lable name ?
label = self.has_alias(i['label'].lower())
if label is None:
label = i['label']
if i['type'] != 'fan_speed':
msg = '{0:15}'.format(label[:15])
else:
msg = '{0:13}'.format(label[:13])
ret.append(self.curse_add_line(msg))
# Temperature could be 'ERR' or 'SLP' (see issue#824)
if i['value'] in (b'ERR', b'SLP'):
msg = '{0:>8}'.format(i['value'])
ret.append(self.curse_add_line(
msg, self.get_views(item=i[self.get_key()],
key='value',
option='decoration')))
else:
if (args.fahrenheit and i['type'] != 'battery' and
i['type'] != 'fan_speed'):
value = to_fahrenheit(i['value'])