Skip to content

Commit

Permalink
bluetooth: reinitialize dbus
Browse files Browse the repository at this point in the history
  • Loading branch information
lasers committed Nov 30, 2023
1 parent bbe43bc commit 7ddb4b6
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions py3status/modules/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"),
Expand All @@ -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()):
Expand Down

0 comments on commit 7ddb4b6

Please sign in to comment.