[core] Refactor engine
This is going to be a bit more comprehensive than anticipated. In order to cleanly refactor the core and the engine, basically start from scratch with the implementation. Goals: * Test coverage * Maintain backwards compatibility with module interface as much as possible (but still make modules easier to code) * Simplicity see #23
This commit is contained in:
parent
20858991b9
commit
a8a6c9bba2
72 changed files with 19 additions and 2155 deletions
|
@ -1,52 +0,0 @@
|
|||
import datetime
|
||||
import bumblebee.module
|
||||
import os.path
|
||||
|
||||
def description():
|
||||
return "Displays battery status, percentage and whether it's charging or discharging."
|
||||
|
||||
def parameters():
|
||||
return [ "battery.device: The device to read from (defaults to BAT0)" ]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._battery = config.parameter("device", "BAT0")
|
||||
self._capacity = 100
|
||||
self._status = "Unknown"
|
||||
|
||||
def widgets(self):
|
||||
self._AC = False;
|
||||
self._path = "/sys/class/power_supply/{}".format(self._battery)
|
||||
if not os.path.exists(self._path):
|
||||
self._AC = True;
|
||||
return bumblebee.output.Widget(self,"AC")
|
||||
|
||||
with open(self._path + "/capacity") as f:
|
||||
self._capacity = int(f.read())
|
||||
self._capacity = self._capacity if self._capacity < 100 else 100
|
||||
|
||||
return bumblebee.output.Widget(self,"{:02d}%".format(self._capacity))
|
||||
|
||||
def warning(self, widget):
|
||||
return self._capacity < self._config.parameter("warning", 20)
|
||||
|
||||
def critical(self, widget):
|
||||
return self._capacity < self._config.parameter("critical", 10)
|
||||
|
||||
def state(self, widget):
|
||||
if self._AC:
|
||||
return "AC"
|
||||
|
||||
with open(self._path + "/status") as f:
|
||||
self._status = f.read().strip()
|
||||
|
||||
if self._status == "Discharging":
|
||||
status = "discharging-{}".format(min([ 10, 25, 50, 80, 100] , key=lambda i:abs(i-self._capacity)))
|
||||
return status
|
||||
else:
|
||||
if self._capacity > 95:
|
||||
return "charged"
|
||||
return "charging"
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
Loading…
Add table
Add a link
Reference in a new issue