diff --git a/bumble/device.py b/bumble/device.py index 8136ff4b..5188448e 100644 --- a/bumble/device.py +++ b/bumble/device.py @@ -2804,23 +2804,13 @@ class Device(CompositeEventEmitter): async def get_pin_code(): 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: - # TODO: make pin code input more flexible, - # so far only numbers are allowed - pin_code = bytes(str(pin_code), encoding='utf8') + pin_code = bytes(pin_code, encoding='utf-8') pin_code_len = len(pin_code) - if pin_code_len > 16: - 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 - + assert 0 < pin_code_len <= 16, "pin_code should be 1-16 bytes" await self.host.send_command( HCI_PIN_Code_Request_Reply_Command( bd_addr=connection.peer_address, @@ -2829,6 +2819,7 @@ class Device(CompositeEventEmitter): ) ) else: + logger.debug("delegate.get_string() returned None") await self.host.send_command( HCI_PIN_Code_Request_Negative_Reply_Command( bd_addr=connection.peer_address