Files
ModemManager/examples/modem-watcher-python
Aleksander Morgado 6175cf562f examples,modem-watcher-python: also monitor modem state updates
$ sudo ./modem-watcher-python
  [ModemWatcher] ModemManager 1.16.6 service is available in bus
  [ModemWatcher] /org/freedesktop/ModemManager1/Modem/0: modem managed by ModemManager [015805000283080]: foxconn (MBIM [105B:E0AB])
  [ModemWatcher] /org/freedesktop/ModemManager1/Modem/0: modem state updated: disabled -> enabling (user-requested)
  [ModemWatcher] /org/freedesktop/ModemManager1/Modem/0: modem state updated: enabling -> enabled (user-requested)
  [ModemWatcher] /org/freedesktop/ModemManager1/Modem/0: modem state updated: enabled -> registered (unknown)
2021-06-21 11:22:29 +02:00
..

The modem-watcher-python program makes use of the 'libmm-glib' library through
GObject Introspection to talk to ModemManager.

The program will just print in stdout whenever:
 * ModemManager is found in the bus
 * ModemManager is lost in the bus
 * A new modem is added to ModemManager
 * A modem is removed from ModemManager

The output will look like this:

$ ./modem-watcher-python
[ModemWatcher] ModemManager service is available in bus
[ModemWatcher] Vodafone (Huawei) (K3772) modem managed by ModemManager [861320000017897]: /org/freedesktop/ModemManager1/Modem/0
[ModemWatcher] modem unmanaged by ModemManager: /org/freedesktop/ModemManager1/Modem/0
[ModemWatcher] ModemManager service not available in bus

Note that the program requires ModemManager and libmm-glib to be installed in
the system and the introspection typelibs available in the standard paths.

Have fun!