diff --git a/scratch_link.py b/scratch_link.py index b12d5a9..55e8df7 100755 --- a/scratch_link.py +++ b/scratch_link.py @@ -434,13 +434,13 @@ class BLESession(Session): def matches(self, dev, filters): """ - Check if the found BLE device mathces the filters Scracth specifies. + Check if the found BLE device matches the filters Scratch specifies. """ logger.debug(f"in matches {dev} {filters}") for f in filters: if 'services' in f: for s in f['services']: - logger.debug(f"sevice to check: {s}") + logger.debug(f"service to check: {s}") given_uuid = s logger.debug(f"given: {given_uuid}") dev_uuid = self._get_dev_uuid(dev) @@ -451,6 +451,16 @@ class BLESession(Session): if given_uuid == dev_uuid: logger.debug("match...") return True + if 'namePrefix' in f: + # 0x08: Shortened Local Name + deviceName = dev.getValueText(0x08) + if not deviceName: + continue + logger.debug(f"Name of \"{deviceName}\" begins with: \"{f['namePrefix']}\"?") + if(deviceName.startswith(f['namePrefix'])): + logger.debug("Yes") + return True + logger.debug("No") if 'name' in f or 'manufactureData' in f: logger.error("name/manufactureData filters not implemented") # TODO: implement other filters defined: @@ -498,7 +508,7 @@ class BLESession(Session): self.status = self.DONE if len(self.found_devices) == 0 and not err_msg: - err_msg = (f"BLE service not found: {params['filters']}. " + err_msg = (f"No BLE device found: {params['filters']}. " "Check BLE device.") res["error"] = { "message": err_msg } logger.error(err_msg)