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)
This commit is contained in:
Aleksander Morgado
2021-06-21 11:22:29 +02:00
parent a357777d39
commit 6175cf562f

View File

@@ -84,23 +84,35 @@ class ModemWatcher:
else: else:
self.set_unavailable() self.set_unavailable()
def on_modem_state_updated(self, modem, old, new, reason):
"""
Modem state updated
"""
print('[ModemWatcher] %s: modem state updated: %s -> %s (%s) ' %
(modem.get_object_path(),
ModemManager.ModemState.get_string (old),
ModemManager.ModemState.get_string (new),
ModemManager.ModemStateChangeReason.get_string (reason)))
def on_object_added(self, manager, obj): def on_object_added(self, manager, obj):
""" """
Object added. Object added.
""" """
modem = obj.get_modem() modem = obj.get_modem()
print('[ModemWatcher] %s (%s) modem managed by ModemManager [%s]: %s' % print('[ModemWatcher] %s: modem managed by ModemManager [%s]: %s (%s)' %
(modem.get_manufacturer(), (obj.get_object_path(),
modem.get_model(),
modem.get_equipment_identifier(), modem.get_equipment_identifier(),
obj.get_object_path())) modem.get_manufacturer(),
modem.get_model()))
if modem.get_state() == ModemManager.ModemState.FAILED: if modem.get_state() == ModemManager.ModemState.FAILED:
print('[ModemWatcher] ignoring failed modem: %s' % print('[ModemWatcher] %s: ignoring failed modem' %
obj.get_object_path()) obj.get_object_path())
else:
modem.connect('state-changed', self.on_modem_state_updated)
def on_object_removed(self, manager, obj): def on_object_removed(self, manager, obj):
""" """
Object removed. Object removed.
""" """
print('[ModemWatcher] modem unmanaged by ModemManager: %s' % print('[ModemWatcher] %s: modem unmanaged by ModemManager' %
obj.get_object_path()) obj.get_object_path())