diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py index 9fd763b2fb..146bd6c33b 100644 --- a/py3status/modules/bluetooth.py +++ b/py3status/modules/bluetooth.py @@ -89,7 +89,7 @@ {'color': '#00FF00', 'full_text': u'Microsoft Bluetooth Notebook Mouse 5000'} """ -from gi.repository import Gio +from gi.repository import Gio, GLiB class Py3status: @@ -105,12 +105,7 @@ class Py3status: thresholds = [(False, "bad"), (True, "good")] def post_config_hook(self): - bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) - iface = "org.freedesktop.DBus.ObjectManager" - self.bluez_manager = Gio.DBusProxy.new_sync( - bus, Gio.DBusProxyFlags.NONE, None, "org.bluez", "/", iface, None - ) - + self._dbus_init() self.names_and_matches = [ ("adapters", "org.bluez.Adapter1"), ("devices", "org.bluez.Device1"), @@ -120,8 +115,30 @@ def post_config_hook(self): for name in ["format", "format_adapter", "format_device"]: self.thresholds_init[name] = self.py3.get_color_names_list(getattr(self, name)) + def _dbus_init(): + bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) + iface = "org.freedesktop.DBus.ObjectManager" + self.bluez_manager = Gio.DBusProxy.new_sync( + bus, Gio.DBusProxyFlags.NONE, None, "org.bluez", "/", iface, None + ) + def _get_bluez_data(self): - objects = self.bluez_manager.GetManagedObjects() + for retry in range(0, 2): + self.py3.log(" --- RETRY {} ---".format(retry)) + try: + objects = self.bluez_manager.GetManagedObjects() + self.py3.log(" --- SUCCESS ---") + except GLiB.Error as err: + self.py3.log(" --- FAILED ---") + if err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.SERVICE_UNKNOWN): + self._dbus_init() + self.py3.log(" --- MATCHED ---") + else: + self.py3.log(" --- RAISED ---") + raise + else: + break + temporary = {} for path, interfaces in sorted(objects.items()):