hddtemp: workaround for hddtemp byte bug
@@ -109,6 +109,7 @@ compact
"""
from telnetlib import Telnet
+from string import printable
class Py3status:
@@ -124,13 +125,24 @@ class Py3status:
def post_config_hook(self):
self.keys = ['path', 'name', 'temperature', 'unit']
+ self.cache_names = {}
def hddtemp(self):
- line = Telnet('localhost', 7634).read_all().decode()[1:-1]
+ line = Telnet('localhost', 7634).read_all().decode('utf-8', 'ignore')
new_data = []
- for chunk in line.split('||'):
+ for chunk in line[1:-1].split('||'):
hdd = dict(zip(self.keys, chunk.split('|')))
+ # workaround for hddtemp byte bug
+ try:
+ hdd['name'] = self.cache_names[hdd['name']]
+ except KeyError:
+ key = ''.join(
+ [x for x in hdd['name'] if x in printable]).strip()
+ if key.endswith('G B') and key[-4].isdigit():
+ key = 'GB'.join(key.rsplit('G B', 1))
+ hdd['name'] = self.cache_names[hdd['name']] = key
+
self.py3.threshold_get_color(hdd['temperature'], 'temperature')
new_data.append(self.py3.safe_format(self.format_hdd, hdd))
