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

PySwitchBot 0.15.0 #103

Closed
CordMaster opened this issue Jul 23, 2022 · 7 comments
Closed

PySwitchBot 0.15.0 #103

CordMaster opened this issue Jul 23, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@CordMaster
Copy link

It seems that the version of PySwitchBot used is a bit out of date and using pybluez. While this is not an issue right now, recent versions have moved to Bleak as the Bluetooth LE backend, and now use an async API as opposed to the blocking one used in 0.12.0. Are there any plans to move to an async loop and support newer versions?

One option would be to move the MQTT package to https://github.com/sbtinstruments/asyncio-mqtt.

I would be more than happy to help out if this is in the roadmap.

Thanks,
--CordMaster

@fphammerle fphammerle added the enhancement New feature or request label Jul 24, 2022
@fphammerle
Copy link
Owner

Hi @CordMaster, thanks for your suggestions! I am following the changes/updates in PySwitchbot.
Unfortunately, I currently do not have any resources to test the compatibility with the new releases or switch to async mqtt.

@fphammerle
Copy link
Owner

fphammerle commented Jul 24, 2022

Thanks for suggesting sbtinstruments/asyncio-mqtt.
Before switching to a particular mqtt library, I would need to get an overview of the available async mqtt libs and compare them regarding their interface, ease of integration and size of user base.

I would be more than happy to help out if this is in the roadmap.

If you are interested in testing the compatibility with newer versions of pySwitchbot and maybe even the switch to async, I would greatly appreciate help via PRs. Thank you!

@CordMaster
Copy link
Author

Thanks for the response! I absolutely forgot to thank you for your effort on this wonderful library!!

I did do a little tinkering, and found that it does work if (almost) all pySwitchbot commands are run as blocking in their own loop using asyncio.run(...), however there seem to be a bunch of issues with combining threading and asyncio there (I got a bleak error whenever I tried to do two things at once). Additionally, this change also requires a good portion of the unit tests and exception handling code to be rewritten, and I don't want to ruin your 100% coverage 😉. That said, It looks like the newer versions of pySwitchbot would require a switch to an async MQTT library, and a rewrite of most of the codebase. Since all is working well for now (thanks once again!), and I am awfully short on time, I think leaving it as is until a breaking change is made that justifies a huge overhaul is the best option.

Thanks again,
--CordMaster

@fphammerle
Copy link
Owner

Thanks a lot for testing the concurrent/async approach and your feedback!
I hope I'll find time in the upcoming months to modernize switchbot-mqtt in that aspect.
Let's keep the issue open as a reminder :)

@CordMaster
Copy link
Author

Hello once more!

I did a bit of work on the async transition, and from what I can tell it functions well. There is still a bit of work to be done on error handling, and the unit tests need updating, but if you choose to go with asyncio_mqtt you could use this as a base. You can take a look here; just don't want to submit a pr since it really breaks unit tests.

CordMaster@97e2ac8

Thanks,
--CordMaster

@fphammerle
Copy link
Owner

Great! Thanks a lot for publishing your work and reporting back!

@fphammerle
Copy link
Owner

Main branch now supports pySwitchbot's latest release v0.40.1
(e964cce released as pre-release v4.0.0a0 )

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

No branches or pull requests

2 participants