-
Notifications
You must be signed in to change notification settings - Fork 337
Add support for pairing callbacks #1864
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
base: develop
Are you sure you want to change the base?
Add support for pairing callbacks #1864
Conversation
dlech
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for getting this moving again. I've made some preliminary comments. It will take me some time to go back and look at the previous discussions to refresh my memory on all of the details that have been looked at before. And I'll need some time to put something together for testing.
In the meantime, it looks like there is perhaps some preliminary refactoring that could be split out into a separate pull request to keep things moving.
| # we can add a handler for them) and also ensures that the pairing | ||
| # agent will only handle handle requests for this specific connection. | ||
| self._bus: MessageBus = MessageBus( | ||
| bus_type=BusType.SYSTEM, negotiate_unix_fd=True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| bus_type=BusType.SYSTEM, negotiate_unix_fd=True | |
| bus_type=BusType.SYSTEM, negotiate_unix_fd=True, auth=get_dbus_authenticator() |
| negotiate_unix_fd=True, | ||
| auth=get_dbus_authenticator(), | ||
| ).connect() | ||
| if not self._bus.connected: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By not creating a new MessageBus here, it changes the behavoir when when people disconnect and reconnect without stopping notifications first.
I'm not sure we can do this without breaking existing users.
| member="Pair", | ||
| ) | ||
| ) | ||
| reply = await self._pair(self._pairing_callbacks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, there was some slight difference between the pairing here and in self.pair(). I'm guessing that is why self._pair() is introduced.
Can we pull this change out into a separate pull request to make it easier to look at on it's own?
|
|
||
| return services | ||
|
|
||
| def get_device_props(self, device_path: str) -> Device1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to stick with having methods to get individual properties using the _get_device_property() so that we get a more helpful error message when things go wrong.
|
|
||
| if kwargs.get("pairing_callbacks"): | ||
| logger.warn( | ||
| "Pairing is not available in WinRT.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should be "not implemented" rather than "not available".
| """ | ||
| Async version of the builtin input function. | ||
| """ | ||
| return input(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input() is a blocking function, so will break asyncio. We should replace this with something else like aioconsole.
| def __init__(self) -> None: | ||
| super().__init__() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def __init__(self) -> None: | |
| super().__init__() |
This should not be needed.
|
|
||
| print("scanning...") | ||
|
|
||
| device = await BleakScanner.find_device_by_address(addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have the possibility to find by name as well like other examples.
|
@tgagneret-embedded Thanks for picking this back up. We have a lot of Home Assistant users who are really excited about having this feature. As soon as this gets going, I'll work on adding support to ESPHome as well. |
Add support for pairing callbacks.
This is based on: