mirror of
https://github.com/google/bumble.git
synced 2026-05-08 03:58:01 +00:00
Use delegate.get_string to get pin code
This commit is contained in:
@@ -2804,23 +2804,13 @@ class Device(CompositeEventEmitter):
|
|||||||
|
|
||||||
async def get_pin_code():
|
async def get_pin_code():
|
||||||
pin_code = await connection.abort_on(
|
pin_code = await connection.abort_on(
|
||||||
'disconnection', pairing_config.delegate.get_number()
|
'disconnection', pairing_config.delegate.get_string(16)
|
||||||
)
|
)
|
||||||
|
|
||||||
if pin_code is not None:
|
if pin_code is not None:
|
||||||
# TODO: make pin code input more flexible,
|
pin_code = bytes(pin_code, encoding='utf-8')
|
||||||
# so far only numbers are allowed
|
|
||||||
pin_code = bytes(str(pin_code), encoding='utf8')
|
|
||||||
pin_code_len = len(pin_code)
|
pin_code_len = len(pin_code)
|
||||||
if pin_code_len > 16:
|
assert 0 < pin_code_len <= 16, "pin_code should be 1-16 bytes"
|
||||||
logger.warning(
|
|
||||||
'pin_code is longer than 16 bytes, truncated to 16'
|
|
||||||
)
|
|
||||||
pin_code_len = 16
|
|
||||||
# the pin_code will be truncated according to pin_code_len
|
|
||||||
# when converted to byte array in HCI_Object, so we
|
|
||||||
# are not doing truncation here
|
|
||||||
|
|
||||||
await self.host.send_command(
|
await self.host.send_command(
|
||||||
HCI_PIN_Code_Request_Reply_Command(
|
HCI_PIN_Code_Request_Reply_Command(
|
||||||
bd_addr=connection.peer_address,
|
bd_addr=connection.peer_address,
|
||||||
@@ -2829,6 +2819,7 @@ class Device(CompositeEventEmitter):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
logger.debug("delegate.get_string() returned None")
|
||||||
await self.host.send_command(
|
await self.host.send_command(
|
||||||
HCI_PIN_Code_Request_Negative_Reply_Command(
|
HCI_PIN_Code_Request_Negative_Reply_Command(
|
||||||
bd_addr=connection.peer_address
|
bd_addr=connection.peer_address
|
||||||
|
|||||||
Reference in New Issue
Block a user