-
Notifications
You must be signed in to change notification settings - Fork 7
Adapt API for Python async environment #4
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
Adapt API for Python async environment #4
Conversation
|
||
[project] | ||
name = "godice" | ||
authors = [{name = "Particula", email = "iavtomator@gmail.com"}] |
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.
todo - change email once provided
@ParticulaCode @AlexWorland @Geek5510 take a look please |
@anton-ptashnik Hi Anton! First of all, thank you very much for your contributions! Overall, the code seems excellent, and we appreciate you taking the time to work on it. We have two requests we'd like to make before we implement them.
|
- allow to change Dice shell without device reconnection - renaming DiceType -> DiceShell
That's a good question that directed me towards a change. Initially I made a shell to be setup on Dice object creation, but this forces us to create another object when we change a shell and want to receive number updates for a new shell. This leads to redundant device reconnection since connection is handled per an object.
Done. I added more clarifications to demo.py, hope it became easier to understand now. Please review and tell if any other changes needed. |
Amazing work! We'll do some testing on our side and approve it once it's done. Thank you! |
Summary of proposed changes:
For now the API is implemented based on async bleak and wrapped in sync Python functions, spawning additional threads per each connected device. While it may be convenient for simple scripts and demo purposes, it makes difficult to use the API in purely async scripts leveraging Python asyncio since calling any sync function blocks an asyncio loop.
The PR removes intermediate sync wrappers thus making API easy to use in async environment.
Python library code supposed to be used by others usually gets published to a package registry, PyPI for Python. It makes easy to locate and install a package with a single command:
pip install godice
The PR provides a package metadata file used for publishing a package to the PyPI.
For each notification received, a check on dice (shell) type is done to decide how to parse a rolled number. It is not required since a shell type is not going to change for each dice flip.
The PR proposes to pick a shell type per a Dice object on init, then the way notifications are parsed is setup for the object according to a passed shell type.