From 3ffbde35b1e06972ee3a066e2cc7f0af943a35d0 Mon Sep 17 00:00:00 2001 From: Shin'ichiro Kawasaki Date: Sun, 14 Nov 2021 20:46:53 +0900 Subject: [PATCH] BLESession: handle device UUIDs as list In the debug for the issue #30, it turned out that the bluepy API ScanEntry.getValueText() for adtypes may return multiple UUIDs concatenated with comma. Current code assumes that the API returns single UUID, then multiple UUIDs cause the "Error: Non-hexadecimal digit found" for the comma. To fix it, replace ScanEntry.getValueText() call with getValue(), and handle the result as a list of UUIDs. Also rename the helper function _get_dev_uuid() to _get_dev_uuids() accordingly. Signed-off-by: Shin'ichiro Kawasaki --- pyscrlink/scratch_link.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pyscrlink/scratch_link.py b/pyscrlink/scratch_link.py index 607e1c2..314c3b7 100755 --- a/pyscrlink/scratch_link.py +++ b/pyscrlink/scratch_link.py @@ -466,15 +466,14 @@ def close(self): def __del__(self): self.close() - def _get_dev_uuid(self, dev): + def _get_dev_uuids(self, dev): for adtype in self.SERVICE_CLASS_UUID_ADTYPES: - service_class_uuid = dev.getValueText(adtype) - if service_class_uuid: - a = self.SERVICE_CLASS_UUID_ADTYPES[adtype] - logger.debug(f"service class uuid for {a}/{adtype}: {service_class_uuid}") - uuid = UUID(service_class_uuid) - logger.debug(f"uuid: {uuid}") - return uuid + service_class_uuids = dev.getValue(adtype) + if service_class_uuids: + for u in service_class_uuids: + a = self.SERVICE_CLASS_UUID_ADTYPES[adtype] + logger.debug(f"service class uuid for {a}/{adtype}: {u}") + return service_class_uuids return None def matches(self, dev, filters): @@ -488,14 +487,15 @@ def matches(self, dev, filters): logger.debug(f"service to check: {s}") given_uuid = s logger.debug(f"given UUID: {given_uuid} hash={UUID(given_uuid).__hash__()}") - dev_uuid = self._get_dev_uuid(dev) - if not dev_uuid: + dev_uuids = self._get_dev_uuids(dev) + if not dev_uuids: continue - logger.debug(f"dev UUID: {dev_uuid} hash={dev_uuid.__hash__()}") - logger.debug(given_uuid == dev_uuid) - if given_uuid == dev_uuid: - logger.debug("match...") - return True + for u in dev_uuids: + logger.debug(f"dev UUID: {u} hash={u.__hash__()}") + logger.debug(given_uuid == u) + if given_uuid == u: + logger.debug("match...") + return True if 'namePrefix' in f: # 0x08: Shortened Local Name deviceName = dev.getValueText(0x08)