-
Notifications
You must be signed in to change notification settings - Fork 304
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
proposed breaking change: Bleak init fuction #652
Comments
I suppose we could make this less breaking by issuing a warning and calling the init function the first time a scanner is started if it has not already been called. |
Can't we switch to a factory function for the classes instead? We are contemplating a esphome backend for bleak to extend the range of homeassistant bluetooth device trackers for example. In that case we would have multiple backends active at the same time. We could even do it backword compatible by overloading the new function.
|
Yes, that would work, but is still a breaking change. And would probably require more than just adding one line to existing programs. |
Non breaking change with hidden factory function. I suppressed whitespaces for it to be a bit easier to paste here. For example i've not modified the init.cli function that works like before.
|
Thanks for the suggestion. However, some of the features that need to be added to this are async and we can't call async functions from |
This is why I was thinking we could make a new global async init function. Users can call it explicitly if they need custom options or if they want to control exactly when it runs, but we could implicit call it if hasn't be run yet the first time we start scanning (from the async |
I think a breaking change with async factory functions make more sense then. You would still need to do detections to figure out which backend yo use right? |
Yes, that would not change. |
Closing since most of the problems this would solve have been fixed other ways. There is still potentially a need for a |
I've collected a number of cases for needing a Bleak init function. But first I should say that this would be a breaking change because it would require users to modify their code by adding one line like this:
So why do we need such a function?
bleak/bleak/backends/corebluetooth/CentralManagerDelegate.py
Lines 77 to 82 in 41aa0e2
Could address STA vs. MTA issues in WinRT backend here (needed for UI integration).(no longer relevant)Could be used to avoid import side effects (well-behaving Python module should not have side effects on import, like spawning processes, which we are currently doing):(no longer relevant)This is also relevant for STA vs. MTA issues.Would avoid the need hacks like:
_on_rtd = os.environ.get("READTHEDOCS") == "True"
_on_ci = "CI" in os.environ
bleak/bleak/__init__.py
Lines 19 to 20 in 41aa0e2
The text was updated successfully, but these errors were encountered: