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

PyTradfri 2.0: sans-io #29

Closed
balloob opened this issue May 3, 2017 · 2 comments
Closed

PyTradfri 2.0: sans-io #29

balloob opened this issue May 3, 2017 · 2 comments

Comments

@balloob
Copy link
Collaborator

balloob commented May 3, 2017

In the Python community there has been a movement to make Sans-IO libraries. For an intro, see this talk by Cory Benfield at PyCon 2016.

The idea is to separate the parser from the actual sending/receiving of messages so that there can be different implementations. With aiocoap being on the horizon (#28), I want to transform the library to be able to both support a sync and async API.

The code is already organized in such a way that the migration will be fairly painless. All writing is already done via a single method: set_values. Instead of having our methods call the API directly, we will have it return a command object. We then have different APIs that we can give the command to.

The sync API would look like this:

command = light.light_control.set_dimmer(100)
api(command)

If the API wants to consume the response from the command, we can have a callback method be added to the command that can automatically be called by an implementing API.

command = light.update()
yield from api(command)
# Under the hood api calls `command.set_result(result)`
@Hedda
Copy link

Hedda commented Jun 12, 2017

@balloob Any news on movement to Sans-IO libraries?

@balloob
Copy link
Collaborator Author

balloob commented Jun 14, 2017

Closed via #34

@balloob balloob closed this as completed Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants