Battery status update
This commit is contained in:
parent
acaac29906
commit
84f6bdd0c9
@ -10,7 +10,9 @@ class Device(device.Device):
|
||||
|
||||
def __init__(self):
|
||||
device.Device.__init__(self)
|
||||
|
||||
self._level = 0
|
||||
self._timeout_id = gobject.timeout_add(2000, self._check_battery_level)
|
||||
|
||||
def do_get_property(self, pspec):
|
||||
if pspec.name == 'level':
|
||||
@ -18,3 +20,30 @@ class Device(device.Device):
|
||||
|
||||
def get_type(self):
|
||||
return 'battery'
|
||||
|
||||
def _check_battery_level(self):
|
||||
new_level = self._get_battery_level()
|
||||
|
||||
if new_level != self._level:
|
||||
self._level = new_level
|
||||
self.notify('level')
|
||||
|
||||
return True
|
||||
|
||||
def _get_battery_level(self):
|
||||
battery_class_path = '/sys/class/battery/psu_0/'
|
||||
|
||||
capacity_path = battery_class_path + 'capacity_percentage'
|
||||
try:
|
||||
f = open(capacity_path, 'r')
|
||||
val = f.read().split('\n')
|
||||
level = int(val[0])
|
||||
f.close()
|
||||
except:
|
||||
level = 0
|
||||
|
||||
return level
|
||||
|
||||
def __del__(self):
|
||||
gobject.source_remove(self._timeout_id)
|
||||
self._timeout_id = 0
|
||||
|
@ -7,7 +7,7 @@ class DeviceView(canvasicon.CanvasIcon):
|
||||
canvasicon.CanvasIcon.__init__(self)
|
||||
self._model = model
|
||||
|
||||
model.connect('notify::strength', self._level_changed_cb)
|
||||
model.connect('notify::level', self._level_changed_cb)
|
||||
|
||||
self._update_level()
|
||||
|
||||
@ -15,6 +15,6 @@ class DeviceView(canvasicon.CanvasIcon):
|
||||
self.props.icon_name = canvasicon.get_icon_state(
|
||||
_ICON_NAME, self._model.props.level)
|
||||
|
||||
def _level_changed_cb(self, pspec):
|
||||
def _level_changed_cb(self, pspec, param):
|
||||
self._update_level()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user