Skip to content

Commit

Permalink
BLESession: handle device UUIDs as list
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kawasaki committed Nov 14, 2021
1 parent 18e0818 commit 3ffbde3
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions pyscrlink/scratch_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit 3ffbde3

Please sign in to comment.