[modules/sensors2] Update to newest API
This commit is contained in:
parent
665fde5399
commit
6975f179fc
1 changed files with 39 additions and 35 deletions
|
@ -14,23 +14,27 @@ Parameters:
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import bumblebee.util
|
import core.module
|
||||||
import bumblebee.output
|
import core.widget
|
||||||
import bumblebee.engine
|
import core.input
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
import util.cli
|
||||||
def __init__(self, engine, config):
|
import util.format
|
||||||
super(Module, self).__init__(engine, config, None)
|
|
||||||
self._chip = self.parameter('chip', '')
|
|
||||||
self._data = {}
|
|
||||||
self._update()
|
|
||||||
|
|
||||||
self.widgets(self._create_widgets())
|
class Module(core.module.Module):
|
||||||
|
def __init__(self, config=None):
|
||||||
|
super().__init__(config, [])
|
||||||
|
|
||||||
def update(self, widgets):
|
self.__chip = self.parameter('chip', '')
|
||||||
self._update()
|
self.__data = {}
|
||||||
for widget in widgets:
|
self.__update()
|
||||||
self._update_widget(widget)
|
|
||||||
|
self.widgets(self.__create_widgets())
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self.__update()
|
||||||
|
for widget in self.widgets():
|
||||||
|
self.__update_widget(widget)
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
widget_type = widget.get('type', '')
|
widget_type = widget.get('type', '')
|
||||||
|
@ -44,28 +48,28 @@ class Module(bumblebee.engine.Module):
|
||||||
pass
|
pass
|
||||||
return [widget_type]
|
return [widget_type]
|
||||||
|
|
||||||
def _create_widgets(self):
|
def __create_widgets(self):
|
||||||
widgets = []
|
widgets = []
|
||||||
show_temp = bumblebee.util.asbool(self.parameter('showtemp', 'true'))
|
show_temp = util.format.asbool(self.parameter('showtemp', True))
|
||||||
show_fan = bumblebee.util.asbool(self.parameter('showfan', 'true'))
|
show_fan = util.format.asbool(self.parameter('showfan', True))
|
||||||
show_other = bumblebee.util.asbool(self.parameter('showother', 'false'))
|
show_other = util.format.asbool(self.parameter('showother', False))
|
||||||
|
|
||||||
if bumblebee.util.asbool(self.parameter('showcpu', 'true')):
|
if util.format.asbool(self.parameter('showcpu', True)):
|
||||||
widget = bumblebee.output.Widget(full_text=self._cpu)
|
widget = core.widget.Widget(full_text=self.__cpu)
|
||||||
widget.set('type', 'cpu')
|
widget.set('type', 'cpu')
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
|
|
||||||
for adapter in self._data:
|
for adapter in self.__data:
|
||||||
for package in self._data[adapter]:
|
for package in self.__data[adapter]:
|
||||||
if bumblebee.util.asbool(self.parameter('showname', 'false')):
|
if util.format.asbool(self.parameter('showname', False)):
|
||||||
widget = bumblebee.output.Widget(full_text=package)
|
widget = core.widget.Widget(full_text=package)
|
||||||
widget.set('data', self._data[adapter][package])
|
widget.set('data', self._data[adapter][package])
|
||||||
widget.set('package', package)
|
widget.set('package', package)
|
||||||
widget.set('field', '')
|
widget.set('field', '')
|
||||||
widget.set('adapter', adapter)
|
widget.set('adapter', adapter)
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
for field in self._data[adapter][package]:
|
for field in self.__data[adapter][package]:
|
||||||
widget = bumblebee.output.Widget()
|
widget = core.widget.Widget()
|
||||||
widget.set('package', package)
|
widget.set('package', package)
|
||||||
widget.set('field', field)
|
widget.set('field', field)
|
||||||
widget.set('adapter', adapter)
|
widget.set('adapter', adapter)
|
||||||
|
@ -83,10 +87,10 @@ class Module(bumblebee.engine.Module):
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
return widgets
|
return widgets
|
||||||
|
|
||||||
def _update_widget(self, widget):
|
def __update_widget(self, widget):
|
||||||
if widget.get('field', '') == '':
|
if widget.get('field', '') == '':
|
||||||
return # nothing to do
|
return # nothing to do
|
||||||
data = self._data[widget.get('adapter')][widget.get('package')][widget.get('field')]
|
data = self.__data[widget.get('adapter')][widget.get('package')][widget.get('field')]
|
||||||
if 'temp' in widget.get('field'):
|
if 'temp' in widget.get('field'):
|
||||||
widget.full_text(u'{:0.01f}°C'.format(data['input']))
|
widget.full_text(u'{:0.01f}°C'.format(data['input']))
|
||||||
elif 'fan' in widget.get('field'):
|
elif 'fan' in widget.get('field'):
|
||||||
|
@ -94,11 +98,11 @@ class Module(bumblebee.engine.Module):
|
||||||
else:
|
else:
|
||||||
widget.full_text(u'{:0.0f}'.format(data['input']))
|
widget.full_text(u'{:0.0f}'.format(data['input']))
|
||||||
|
|
||||||
def _update(self):
|
def __update(self):
|
||||||
output = bumblebee.util.execute('sensors -u {}'.format(self._chip))
|
output = util.cli.execute('sensors -u {}'.format(self.__chip))
|
||||||
self._data = self._parse(output)
|
self.__data = self.__parse(output)
|
||||||
|
|
||||||
def _parse(self, data):
|
def __parse(self, data):
|
||||||
output = {}
|
output = {}
|
||||||
package = ''
|
package = ''
|
||||||
adapter = None
|
adapter = None
|
||||||
|
@ -107,8 +111,8 @@ class Module(bumblebee.engine.Module):
|
||||||
if 'Adapter' in line:
|
if 'Adapter' in line:
|
||||||
# new adapter
|
# new adapter
|
||||||
line = line.replace('Adapter: ', '')
|
line = line.replace('Adapter: ', '')
|
||||||
output[chip + ' ' + line] = {}
|
adapter = '{} {}'.format(chip, line)
|
||||||
adapter = chip + ' ' + line
|
output[adapter] = {}
|
||||||
chip = line #default - line before adapter is always the chip
|
chip = line #default - line before adapter is always the chip
|
||||||
if not adapter: continue
|
if not adapter: continue
|
||||||
key, value = (line.split(':') + ['', ''])[:2]
|
key, value = (line.split(':') + ['', ''])[:2]
|
||||||
|
@ -131,7 +135,7 @@ class Module(bumblebee.engine.Module):
|
||||||
pass
|
pass
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def _cpu(self, _):
|
def __cpu(self, _):
|
||||||
mhz = None
|
mhz = None
|
||||||
try:
|
try:
|
||||||
output = open('/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq').read()
|
output = open('/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq').read()
|
||||||
|
|
Loading…
Reference in a new issue