Repository: qtile/qtile

Issue:
Bluetooth widget displays adapter name instead of name of connected device
### The issue:

version: 0.21.0
log: no relevant log

I configured the bluetooth-widget.
When a device is connected, it shows the adapter name, instead of the device name.

### Required:

- [X] I have searched past issues to see if this bug has already been reported.


Discussion:
Interesting. I can see how that might happen from the code. I'll work on a fix later and would be grateful if you could test it.
Sure I can test it then
Update:
I am running 0.21.1.dev106+g5161618c now and the device shows correctly
I haven't changed anything yet so I suspect the bug is still there, it's just unexpected that you hit it. 

I'll still work on a fix. 

Resolving patch:
diff --git a/libqtile/widget/bluetooth.py b/libqtile/widget/bluetooth.py
--- a/libqtile/widget/bluetooth.py
+++ b/libqtile/widget/bluetooth.py
@@ -72,7 +72,7 @@ async def _init_adapter(self):
 
         powered = await iface.get_powered()
         # subscribe receiver to property changed
-        props.on_properties_changed(self._signal_received)
+        props.on_properties_changed(self._adapter_signal_received)
         return powered
 
     async def _init_device(self):
@@ -86,15 +86,20 @@ async def _init_device(self):
         connected = await iface.get_connected()
         name = await iface.get_name()
         # subscribe receiver to property changed
-        props.on_properties_changed(self._signal_received)
+        props.on_properties_changed(self._device_signal_received)
         return connected, name
 
-    def _signal_received(self, interface_name, changed_properties, _invalidated_properties):
+    def _adapter_signal_received(
+        self, interface_name, changed_properties, _invalidated_properties
+    ):
         powered = changed_properties.get("Powered", None)
         if powered is not None:
             self.powered = powered.value
             self.update_text()
 
+    def _device_signal_received(
+        self, interface_name, changed_properties, _invalidated_properties
+    ):
         connected = changed_properties.get("Connected", None)
         if connected is not None:
             self.connected = connected.value


Test patch:
diff --git a/test/widgets/test_bluetooth.py b/test/widgets/test_bluetooth.py
--- a/test/widgets/test_bluetooth.py
+++ b/test/widgets/test_bluetooth.py
@@ -93,11 +93,15 @@ def new_update(self, text):
     widget.update_text()
     assert widget.text == "Mock Bluetooth Device"
 
-    widget._signal_received(None, {"Name": Variant("s", "New Device Name")}, None)
+    widget._device_signal_received(None, {"Name": Variant("s", "New Device Name")}, None)
     assert widget.text == "New Device Name"
 
-    widget._signal_received(None, {"Connected": Variant("b", False)}, None)
+    # Ignore Name change on the adapter
+    widget._adapter_signal_received(None, {"Name": Variant("s", "New Adapter Name")}, None)
+    assert widget.text == "New Device Name"
+
+    widget._device_signal_received(None, {"Connected": Variant("b", False)}, None)
     assert widget.text == "on"
 
-    widget._signal_received(None, {"Powered": Variant("b", False)}, None)
+    widget._adapter_signal_received(None, {"Powered": Variant("b", False)}, None)
     assert widget.text == "off"