mirror of
https://github.com/kawasaki/pyscrlink.git
synced 2025-09-05 17:20:20 +02:00
BLESession: Print device name in log
In logger.* the device was printed out as "<bluepy.btle.Peripheral object at 0x************>" which is not very useful to the user. Print the deviceName variable instead. Also add missing "f" for f-Strings.
This commit is contained in:
committed by
Shin'ichiro Kawasaki
parent
698447d18f
commit
e281543cb8
@@ -427,13 +427,15 @@ class BLESession(Session):
|
||||
self.status = self.INITIAL
|
||||
self.found_devices = []
|
||||
self.device = None
|
||||
self.deviceName = None
|
||||
self.perip = None
|
||||
self.delegate = None
|
||||
|
||||
def close(self):
|
||||
self.status = self.DONE
|
||||
if self.perip:
|
||||
logger.info(f"disconnect from the BLE peripheral: {self.perip}")
|
||||
logger.info("disconnect from the BLE peripheral: "
|
||||
f"{self.deviceName}")
|
||||
with self.lock:
|
||||
self.perip.disconnect()
|
||||
self.perip = None
|
||||
@@ -453,7 +455,7 @@ class BLESession(Session):
|
||||
"""
|
||||
Check if the found BLE device matches the filters Scratch specifies.
|
||||
"""
|
||||
logger.debug(f"in matches {dev} {filters}")
|
||||
logger.debug(f"in matches {dev.addr} {filters}")
|
||||
for f in filters:
|
||||
if 'services' in f:
|
||||
for s in f['services']:
|
||||
@@ -545,12 +547,13 @@ class BLESession(Session):
|
||||
elif self.status == self.DISCOVERY and method == 'connect':
|
||||
logger.debug("connecting to the BLE device")
|
||||
self.device = self.found_devices[params['peripheralId']]
|
||||
self.deviceName = self.device.getValueText(0x9) or self.device.getValueText(0x8)
|
||||
try:
|
||||
self.perip = Peripheral(self.device.addr,
|
||||
self.device.addrType)
|
||||
logger.info(f"connected to the BLE peripheral: {self.perip}")
|
||||
logger.info(f"connected to the BLE peripheral: {self.deviceName}")
|
||||
except BTLEDisconnectError as e:
|
||||
logger.error(f"failed to connect to the BLE device: {e}")
|
||||
logger.error(f"failed to connect to the BLE device \"{self.deviceName}\": {e}")
|
||||
self.status = self.DONE
|
||||
|
||||
if self.perip:
|
||||
@@ -559,7 +562,7 @@ class BLESession(Session):
|
||||
self.delegate = self.BLEDelegate(self)
|
||||
self.perip.withDelegate(self.delegate)
|
||||
else:
|
||||
err_msg = f"BLE connect failed :{self.device}"
|
||||
err_msg = f"BLE connect failed: {self.deviceName}"
|
||||
res["error"] = { "message": err_msg }
|
||||
self.status = self.DONE
|
||||
|
||||
@@ -569,7 +572,7 @@ class BLESession(Session):
|
||||
chara_id = params['characteristicId']
|
||||
c = self._get_characteristic(chara_id)
|
||||
if not c or c.uuid != UUID(chara_id):
|
||||
logger.error("Failed to get characteristic {chara_id}")
|
||||
logger.error(f"Failed to get characteristic {chara_id}")
|
||||
self.status = self.DONE
|
||||
else:
|
||||
with self.lock:
|
||||
@@ -597,7 +600,7 @@ class BLESession(Session):
|
||||
chara_id = params['characteristicId']
|
||||
c = self._get_characteristic(chara_id)
|
||||
if not c or c.uuid != UUID(chara_id):
|
||||
logger.error("Failed to get characteristic {chara_id}")
|
||||
logger.error(f"Failed to get characteristic {chara_id}")
|
||||
self.status = self.DONE
|
||||
else:
|
||||
if params['encoding'] != 'base64':
|
||||
|
Reference in New Issue
Block a user