Search code examples
pythonsignalsdbus

Python-dbus extra param to add_signal_receiver


I'd like to pass extra param to add_signal_receiver or get somehow path the signal was received from. Now it's defined like that:

bus.add_signal_receiver(handle_signal, 'RemoteDeviceFound', 'org.bluez.Adapter', 'org.bluez', '/org/bluez/hci'+x)

def handle_signal(address, cls, rssi):
    xxxx

I wan't to have many signal receivers at the same time and be able to read 'x' inside handle_signal function.


Solution

  • The Python DBUS documenation has your answer. It provides the following example to pass the sender to the handler function:

    def handler(sender=None):
        print "got signal from %r" % sender
    
    iface.connect_to_signal("Hello", handler, sender_keyword='sender')
    

    So, instead of using bus.add_signal_receiver, create an interface for the signal providing object first and then connect to the signal as in the example.