test: Move paired device removal to separate method
authorTimo Mueller <timo.mueller@bmw-carit.de>
Fri, 6 Dec 2013 07:58:39 +0000 (08:58 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Sat, 7 Dec 2013 01:27:09 +0000 (02:27 +0100)
To prepare the test script for the integration with BlueZ5 the code
specific to BlueZ has been refactored into a separate method.

test/bt-handover

index 980f812..b4ead09 100755 (executable)
@@ -28,25 +28,28 @@ def device_removed(path, interfaces):
                        mainloop.quit()
                        break
 
-if __name__ == '__main__':
-       dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+def remove_paired_devices():
+       bluez_manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+                                       "org.bluez.Manager")
 
-       bus = dbus.SystemBus()
-
-        bluez_manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
-       
        bluez_adapter_path = bluez_manager.DefaultAdapter()
+       bluez_adapter = dbus.Interface(bus.get_object("org.bluez",
+                                               bluez_adapter_path),
+                                               "org.bluez.Adapter")
 
-       bluez_adapter = dbus.Interface(bus.get_object("org.bluez", bluez_adapter_path),
-                                                       "org.bluez.Adapter")
+       print("Using %s" % bluez_adapter.object_path)
 
        for bluez_path in bluez_adapter.ListDevices():
                print("Removing %s" % (bluez_path))
                bluez_adapter.RemoveDevice(bluez_path)
 
+if __name__ == '__main__':
+       dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+       bus = dbus.SystemBus()
 
        adapter_path = neardutils.find_adapter().object_path
-        print("Adapter path %s" % (adapter_path))
+       print("Adapter path %s" % (adapter_path))
        adapter = dbus.Interface(bus.get_object("org.neard", adapter_path),
                                                        "org.neard.Adapter")
 
@@ -56,6 +59,8 @@ if __name__ == '__main__':
        if (powered == dbus.Boolean(0)):
                adapter_props.Set("org.neard.Adapter", "Powered", dbus.Boolean(1))
 
+       remove_paired_devices()
+
        polling = adapter_props.Get("org.neard.Adapter", "Polling")
        if (polling == dbus.Boolean(0)):
                adapter.StartPollLoop("Initiator")