[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: PyQt 6.6.1 QBluetoothDeviceInfo getServiceData() Bug
From: Benjamin Griffiths <ben () familygriffiths ! me ! uk>
Date: 2024-04-12 9:51:38
Message-ID: 942393554.11290823.1712915498404 () email ! ionos ! co ! uk
[Download RAW message or body]
[Attachment #2 (unknown)]
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="default-style">
Hi there,
</div>
<div class="default-style">
</div>
<div class="default-style">
I am trying to read the BLE service data from \
<strong>QBluetoothDeviceInfo</strong> via the <strong>serviceData()</strong> method, \
but I believe I have discovered a bug. </div>
<div class="default-style">
</div>
<div class="default-style"> <em><span class="mtk1">serviceData() </span><span \
class="mtk10">-></span></em><span class="mtk1"><em> Dict[QBluetoothUuid, \
QByteArray]</em><br><br>The function returns an empty dictionary for discovered \
devices that have no service data available (correct behaviour). However, when the \
device <strong>does</strong> have service data, a <strong>TypeError</strong> is \
raised.</span> </div>
<div class="default-style">
</div>
<div class="default-style"> <em><span class="mtk1">TypeError: unhashable type: \
'QBluetoothUuid'</span></em> </div>
<div class="default-style">
</div>
<div class="default-style"> <span class="mtk1">I have attached a minimal \
reproducible example that scans for all Bluetooth Low Energy devices and tries to \
read the service data using serviceData(). Obviously to reproduce this error you will \
need to be in range of some BLE devices that have non-empty service data.</span> \
</div> <div class="default-style">
</div>
<div class="default-style"> <span class="mtk1">I am using Python 3.10.11 and PyQt \
6.6.1.</span> </div>
<div class="default-style">
</div>
<div class="default-style"> <span class="mtk1"><span class="mtk1">A work around is \
to use the </span></span>serviceUuids() method, then use serviceData(uuid) for each \
UUID. However as per the documentation this only return the "first" item in service \
data, not all of it. </div>
<div class="default-style">
</div>
<div class="default-style"> <span class="mtk1">Any support would be greatly \
appreciated.</span> </div>
<div class="default-style">
</div>
<div class="default-style"> <span class="mtk1">Many thanks,</span>
</div>
<div class="default-style">
</div>
<div class="default-style"> <span class="mtk1">Ben</span>
</div>
</body>
</html>
["ble_service_data_bug.py" (text/x-python)]
"""
"""
import sys
from PyQt6.QtBluetooth import QBluetoothDeviceDiscoveryAgent, QBluetoothDeviceInfo
from PyQt6.QtWidgets import QApplication, QMainWindow
class Main(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.show()
self.agent = QBluetoothDeviceDiscoveryAgent()
self.agent.deviceDiscovered.connect(self.on_device_discovered)
self.agent.start(QBluetoothDeviceDiscoveryAgent.DiscoveryMethod.LowEnergyMethod)
def on_device_discovered(self, device: QBluetoothDeviceInfo) -> None:
# check if device is low-energy
if (
device.coreConfigurations()
and QBluetoothDeviceInfo.CoreConfiguration.LowEnergyCoreConfiguration
):
service_data = device.serviceData()
print("Service Data:", service_data)
if __name__ == "__main__":
app = QApplication(sys.argv)
main = Main()
sys.exit(app.exec())
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic