summaryrefslogtreecommitdiffstats
path: root/powermanager/hal-test.py
diff options
context:
space:
mode:
Diffstat (limited to 'powermanager/hal-test.py')
-rw-r--r--powermanager/hal-test.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/powermanager/hal-test.py b/powermanager/hal-test.py
new file mode 100644
index 0000000..f9ef90c
--- /dev/null
+++ b/powermanager/hal-test.py
@@ -0,0 +1,35 @@
+import dbus
+
+bus = dbus.SystemBus()
+hal_manager_obj = bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager")
+hal_manager = dbus.Interface(hal_manager_obj, "org.freedesktop.Hal.Manager")
+#device_names = hal_manager.GetAllDevices()
+
+ac = hal_manager.FindDeviceByCapability("ac_adapter")
+
+#all_devices = hal_manager.GetAllDevices()
+
+#for n in device_names: print n
+#obj = bus.get_object("org.freedesktop.Hal", u'/org/freedesktop/Hal/devices/acpi_AC')
+#obj.GetAllProperties()
+
+name = ac[0]
+device_dbus_obj = bus.get_object("org.freedesktop.Hal" ,ac[0])
+properties = device_dbus_obj.GetAllProperties(dbus_interface="org.freedesktop.Hal.Device")
+
+try:
+ parent_name = properties["info.parent"]
+except KeyError:
+ # no parent, must be parent of virtual_root
+ parent_name = "/"
+except TypeError:
+ print "Error: no properties for device %s"%name
+ #continue
+print properties['ac_adapter.present']
+#for p in properties:
+# print p, " :: ", properties[p]
+if properties['ac_adapter.present']:
+ print "plugged in"
+else:
+ print "unplugged"
+