aboutsummaryrefslogtreecommitdiffstats
path: root/examples/dbus/test_bt_search_devices.py
blob: a4d1c53b10c784656f0d01600984cb934e46a780 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python

import dbus
from efl import dbus_mainloop
from efl import ecore


def disc_started_signal():
    print("Signal: DiscoveryStarted()")


def rem_dev_found_signal(address, cls, rssi):
    print("Signal: RemoteDeviceFound(%s, %s, %s)" % (address, cls, rssi))


def rem_dev_name_signal(address, name):
    print("Signal: RemoteNameUpdated(%s, %s)" % (address, name))


def disc_completed_signal():
    print("Signal: DiscoveryCompleted()")
    ecore.idler_add(ecore.main_loop_quit)


dbus_ml = dbus_mainloop.DBusEcoreMainLoop()
bus = dbus.SystemBus(mainloop=dbus_ml)

bus.add_signal_receiver(disc_started_signal,
                        "DiscoveryStarted",
                        "org.bluez.Adapter",
                        "org.bluez",
                        "/org/bluez/hci0")
bus.add_signal_receiver(rem_dev_found_signal,
                        "RemoteDeviceFound",
                        "org.bluez.Adapter",
                        "org.bluez",
                        "/org/bluez/hci0")
bus.add_signal_receiver(rem_dev_name_signal,
                        "RemoteNameUpdated",
                        "org.bluez.Adapter",
                        "org.bluez",
                        "/org/bluez/hci0")
bus.add_signal_receiver(disc_completed_signal,
                        "DiscoveryCompleted",
                        "org.bluez.Adapter",
                        "org.bluez",
                        "/org/bluez/hci0")

obj = bus.get_object("org.bluez", "/org/bluez/hci0")
adapter = dbus.Interface(obj, "org.bluez.Adapter")

adapter.DiscoverDevices()
ecore.main_loop_begin()