While other signals work fine (PropertiesChanged and DeviceAdded among others) I was not able to get a notification for DeviceRemoved. My sample code is a modified listener.py example:
import dbus.mainloop.glib
from gi.repository import GObject, GLib
import NetworkManager
import time
def out(msg):
print("%s %s" % (time.strftime('%H:%M:%S'), msg))
def statechange(nm, interface, signal, state):
out("State changed to %s" % NetworkManager.const('STATE', state))
def adddevice(nm, interface, signal, device_path):
try:
out("Device %s added" % device_path.IpInterface)
except NetworkManager.ObjectVanished:
# Sometimes this signal is sent for *removed* devices. Ignore.
pass
def removedevice(*args, **kw):
out("removedevice: {} {}".format(args, kw))
def main():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
NetworkManager.NetworkManager.OnStateChanged(statechange)
NetworkManager.NetworkManager.OnDeviceAdded(adddevice)
NetworkManager.NetworkManager.OnDeviceRemoved(removedevice)
loop = GObject.MainLoop()
loop.run()
if __name__ == '__main__':
main()
While other signals work fine (
PropertiesChanged
andDeviceAdded
among others) I was not able to get a notification forDeviceRemoved
. My sample code is a modifiedlistener.py
example: