Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2007-07-10 10:35:00 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2007-07-10 10:35:00 (GMT)
commitdae54f34ae9b230a695c502f811667f82f7e2fc5 (patch)
treed2bb18ef6e702491c38292ea91da082a08be4a25 /shell
parent7900e6c486938692f8ed2ba61fd73d8f5b488246 (diff)
Do not fail if cannot access the HAL battery properties.
Diffstat (limited to 'shell')
-rw-r--r--shell/model/devices/battery.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/shell/model/devices/battery.py b/shell/model/devices/battery.py
index cdb4994..853d00e 100644
--- a/shell/model/devices/battery.py
+++ b/shell/model/devices/battery.py
@@ -14,6 +14,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+import logging
+
import gobject
import dbus
@@ -45,9 +47,30 @@ class Device(device.Device):
'org.freedesktop.Hal',
udi)
- self._level = self._battery.GetProperty(_LEVEL_PROP)
- self._charging = self._battery.GetProperty(_CHARGING_PROP)
- self._discharging = self._battery.GetProperty(_DISCHARGING_PROP)
+ self._level = self._get_level()
+ self._charging = self._get_charging()
+ self._discharging = self._get_discharging()
+
+ def _get_level(self):
+ try:
+ return self._battery.GetProperty(_LEVEL_PROP)
+ except dbus.DBusException:
+ logging.error('Cannot access %s' % _LEVEL_PROP)
+ return 0
+
+ def _get_charging(self):
+ try:
+ return self._battery.GetProperty(_CHARGING_PROP)
+ except dbus.DBusException:
+ logging.error('Cannot access %s' % _CHARGING_PROP)
+ return False
+
+ def _get_discharging(self):
+ try:
+ return self._battery.GetProperty(_DISCHARGING_PROP)
+ except dbus.DBusException:
+ logging.error('Cannot access %s' % _DISCHARGING_PROP)
+ return False
def do_get_property(self, pspec):
if pspec.name == 'level':
@@ -63,11 +86,11 @@ class Device(device.Device):
def _battery_changed(self, num_changes, changes_list):
for change in changes_list:
if change[0] == _LEVEL_PROP:
- self._level = self._battery.GetProperty(_LEVEL_PROP)
+ self._level = self._get_level()
self.notify('level')
elif change[0] == _CHARGING_PROP:
- self._charging = self._battery.GetProperty(_CHARGING_PROP)
+ self._charging = self._get_charging()
self.notify('charging')
elif change[0] == _DISCHARGING_PROP:
- self._discharging = self._battery.GetProperty(_DISCHARGING_PROP)
+ self._discharging = self._get_discharging()
self.notify('discharging')