import dbus
bus = dbus.SystemBus()
hal_obj = bus.get_object ('org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
hal = dbus.Interface (hal_obj, 'org.freedesktop.Hal.Manager')
uids = hal.FindDeviceByCapability('battery')
dev_obj = bus.get_object ('org.freedesktop.Hal', uids[0])
print 'charge level percentage',\
dev_obj.GetProperty('battery.charge_level.percentage')
print 'charge current', dev_obj.GetProperty('battery.reporting.current')
print 'charge design', dev_obj.GetProperty('battery.reporting.design')
print 'charge last full',\
dev_obj.GetProperty('battery.reporting.last_full')
print 'charge unit', dev_obj.GetProperty('battery.reporting.unit')
print 'voltage current', dev_obj.GetProperty('battery.voltage.current')
print 'voltage design', dev_obj.GetProperty('battery.voltage.design')
print 'voltage unit', dev_obj.GetProperty('battery.voltage.unit')
This little snippet of Python code talks to the HAL layer through D-Bus, and in that way is capable of coming up with quite a lot of information about the battery. Check the complete HAL battery API for more information about what can be read through these calls.
No comments:
Post a Comment