Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

programmatically accept pairing request in python without dialog interaction #827

Open
mitea1 opened this issue May 9, 2022 · 4 comments · May be fixed by #1100
Open

programmatically accept pairing request in python without dialog interaction #827

mitea1 opened this issue May 9, 2022 · 4 comments · May be fixed by #1100
Labels
enhancement New feature or request

Comments

@mitea1
Copy link

mitea1 commented May 9, 2022

  • bleak version: 0.14.3
  • Python version: 3.7.3
  • Operating System: Win10 (and Linux)
  • BlueZ version (bluetoothctl -v) in case of Linux: 5.50

Description

Looking for a way to accept pairing request during integration tests without dialog action in windows. also want to understand what would be needed to do the same in a linux environment

What I Did

used BleakClient.pair(). works if I wait and confirm pairing in dialog. but I'm looking for a way to do that by code.

@hbldh
Copy link
Owner

hbldh commented May 9, 2022

In Windows, the pairing is already designed to be "Just Works" without any user interaction:
https://github.com/hbldh/bleak/blob/develop/bleak/backends/winrt/client.py#L367-L368

A pairing request is sent and the method in the link above should just accept the pairing without any further processing needed.

If a dialog is brought up, then that is a change in how Windows handles pairing. I did not get a dialog when I paired the last time.

From the Microsoft UWP docs concering the ConfirmOnly solution:

The application must confirm they wish to perform the pairing action. You can present an optional confirmation dialog to the user. With a value of ConfirmOnly, call Accept from the event args of the PairingRequested event handler if you want the pairing to complete.

For integration tests, just monkeypatch the pair function on the client to this

async def mock_pair_success(client, protection_level: int = None, **kwargs) -> bool:
    return True

client.pair = mock_pair_success

You will never be able to test pairing without performing the actual pairing with Bleak, since it uses the OS native BLE APIs. You could possible monkeypatch the CustomPairing class from the winrt package, but I do not think you will gain anything by doing that...

@mitea1
Copy link
Author

mitea1 commented May 9, 2022

If a dialog is brought up, then that is a change in how Windows handles pairing. I did not get a dialog when I paired the last time.

using Windows version 10.0.19042 Build 19042. it's not latest and greatest

You will never be able to test pairing without performing the actual pairing with Bleak, since it uses the OS native BLE APIs. You could possible monkeypatch the CustomPairing class from the winrt package, but I do not think you will gain anything by doing that...

I don't want to prevent pairing at all I just want to do it in a way that I don't need to process any user dialog. just processing it in code or automatically if possible.

should just works (like you describe for windows above) also work in a linux environment?

@dlech
Copy link
Collaborator

dlech commented May 9, 2022

This is not technically possible on macOS. For Windows and Linux, there is a pull request open for this, but it has been stalled. #640

@sfoley-gpqa
Copy link

This is not technically possible on macOS. For Windows and Linux, there is a pull request open for this, but it has been stalled. #640

This is a problem for my team's work in MacOS 12+ right now. :(

@dlech dlech added the enhancement New feature or request label Jul 13, 2022
@dlech dlech linked a pull request Jul 13, 2022 that will close this issue
@dlech dlech linked a pull request Oct 31, 2022 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants