Logo Search packages:      
Sourcecode: guidance-power-manager version File versions

def powermanage::PowerManage::getBatteryState (   self,
  batt 
)

Read battery status from HAL and return 
    (battery state, charge percentage, remaining seconds). 

Definition at line 206 of file powermanage.py.

00206                                   :
        """ Read battery status from HAL and return 
            (battery state, charge percentage, remaining seconds). 
        """
        try:
            properties = self.batteries[batt].GetAllProperties(dbus_interface="org.freedesktop.Hal.Device")
        except dbus.DBusException:
            print "problem getting battery state from dbus."
            return "not present", 0, 0, 0, 0, 0
        
        if not properties['battery.present']:
            return "not present", 0, 0, 0, 0, 0
        else:
            current = full = level = remain = rate = 0
            if properties.has_key("battery.charge_level.current"):
                current = properties["battery.charge_level.current"]
            if properties.has_key("battery.charge_level.last_full"):
                full = properties["battery.charge_level.last_full"]

            if properties["battery.rechargeable.is_charging"]:
                state = "charging"
            elif properties["battery.rechargeable.is_discharging"]:
                if self.onBattery():
                    state = "discharging"
                else:
                    state = "charged"
            elif not properties["battery.rechargeable.is_discharging"] \
                 and not properties["battery.rechargeable.is_charging"]:
                if current == 0:
                    state = "empty"
                else:
                    state = "charged"
            else:
                print "Unknown battery state ..."

            # Sometimes, HAL doesn't report the percentage, but we can compute that ourselves anyway
            if properties.has_key("battery.charge_level.percentage"):
                level = properties["battery.charge_level.percentage"]
            elif current > 0 and full > 0:
                level = current / full

            if state in ("charging","discharging"):
                if properties.has_key("battery.remaining_time"):
                    remain = properties["battery.remaining_time"]
                if properties.has_key("battery.charge_level.rate"):
                    rate = properties["battery.charge_level.rate"]

            return state, level, remain, rate, current, full

    def showInfo(self):


Generated by  Doxygen 1.6.0   Back to index