[modules/hddtemp] Update to new API
This commit is contained in:
parent
52ca6e5a43
commit
658fbd2c1c
1 changed files with 23 additions and 23 deletions
|
@ -6,8 +6,8 @@ that runs on localhost and default port (7634)
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
import bumblebee.engine
|
import core.module
|
||||||
import bumblebee.output
|
import core.widget
|
||||||
|
|
||||||
HOST = 'localhost'
|
HOST = 'localhost'
|
||||||
PORT = 7634
|
PORT = 7634
|
||||||
|
@ -16,17 +16,15 @@ CHUNK_SIZE = 1024
|
||||||
RECORD_SIZE = 5
|
RECORD_SIZE = 5
|
||||||
SEPARATOR = '|'
|
SEPARATOR = '|'
|
||||||
|
|
||||||
|
class Module(core.module.Module):
|
||||||
|
def __init__(self, config):
|
||||||
|
super().__init__(config, core.widget.Widget(self.hddtemps))
|
||||||
|
self.__hddtemps = self.__get_hddtemps()
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
def hddtemps(self, _):
|
||||||
def __init__(self, engine, config):
|
return self.__hddtemps
|
||||||
widget = bumblebee.output.Widget(full_text=self.hddtemps)
|
|
||||||
super(Module, self).__init__(engine, config, widget)
|
|
||||||
self._hddtemps = self._get_hddtemps()
|
|
||||||
|
|
||||||
def hddtemps(self, __):
|
def __fetch_data(self):
|
||||||
return self._hddtemps
|
|
||||||
|
|
||||||
def _fetch_data(self):
|
|
||||||
"""fetch data from hddtemp service"""
|
"""fetch data from hddtemp service"""
|
||||||
try:
|
try:
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||||
|
@ -43,7 +41,7 @@ class Module(bumblebee.engine.Module):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_parts(data):
|
def __get_parts(data):
|
||||||
"""
|
"""
|
||||||
split data using | separator and remove first item
|
split data using | separator and remove first item
|
||||||
(because the first item is empty)
|
(because the first item is empty)
|
||||||
|
@ -52,7 +50,7 @@ class Module(bumblebee.engine.Module):
|
||||||
return parts
|
return parts
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _partition_parts(parts):
|
def __partition_parts(parts):
|
||||||
"""
|
"""
|
||||||
partition parts: one device record is five (5) items
|
partition parts: one device record is five (5) items
|
||||||
"""
|
"""
|
||||||
|
@ -61,7 +59,7 @@ class Module(bumblebee.engine.Module):
|
||||||
return per_disk
|
return per_disk
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_name_and_temp(device_record):
|
def __get_name_and_temp(device_record):
|
||||||
"""
|
"""
|
||||||
get device name (without /dev part, to save space on bar)
|
get device name (without /dev part, to save space on bar)
|
||||||
and temperature (in °C) as tuple
|
and temperature (in °C) as tuple
|
||||||
|
@ -71,20 +69,22 @@ class Module(bumblebee.engine.Module):
|
||||||
return (device_name, device_temp)
|
return (device_name, device_temp)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_hddtemp(device_record):
|
def __get_hddtemp(device_record):
|
||||||
name, temp = device_record
|
name, temp = device_record
|
||||||
hddtemp = '{}+{}°C'.format(name, temp)
|
hddtemp = '{}+{}°C'.format(name, temp)
|
||||||
return hddtemp
|
return hddtemp
|
||||||
|
|
||||||
def _get_hddtemps(self):
|
def __get_hddtemps(self):
|
||||||
data = self._fetch_data()
|
data = self.__fetch_data()
|
||||||
if data is None:
|
if data is None:
|
||||||
return 'n/a'
|
return 'n/a'
|
||||||
parts = self._get_parts(data)
|
parts = self.__get_parts(data)
|
||||||
per_disk = self._partition_parts(parts)
|
per_disk = self.__partition_parts(parts)
|
||||||
names_and_temps = [self._get_name_and_temp(x) for x in per_disk]
|
names_and_temps = [self.__get_name_and_temp(x) for x in per_disk]
|
||||||
hddtemps = [self._get_hddtemp(x) for x in names_and_temps]
|
hddtemps = [self.__get_hddtemp(x) for x in names_and_temps]
|
||||||
return SEPARATOR.join(hddtemps)
|
return SEPARATOR.join(hddtemps)
|
||||||
|
|
||||||
def update(self, __):
|
def update(self):
|
||||||
self._hddtemps = self._get_hddtemps()
|
self.__hddtemps = self.__get_hddtemps()
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue