Add mouse HID actions and make NanoKVMClient a context manager#10
Add mouse HID actions and make NanoKVMClient a context manager#10puddly merged 1 commit intopuddly:devfrom
Conversation
|
What about a context manager API? It can be a breaking change. Any async cleanup in async with ClientSession() as session:
async with NanoKVMClient(...) as client:
...Then, |
|
I suspect we probably should have constants for the buttons "left" "right" "middle", etc .. |
Yes, you are right. Look at my last patch, I think it would be clean, and using a context manager, we can even create the ClientSession automatically. It's made to be backwards compatible. I am testing it out right now. will report back and clear the draft. |
a1ed077 to
d17497d
Compare
nanokvm/client.py
Outdated
| async def close(self) -> None: | ||
| """Close all connections and cleanup resources.""" | ||
| await self.close_ws() | ||
| if self._session is not None: # Defensive check for idempotency | ||
| await self._session.close() | ||
| self._session = None |
There was a problem hiding this comment.
I can probably pull this all under aexit
There was a problem hiding this comment.
If we only support a context manager, yeah, that would be best. I don't think anything will break with a double close but there's no need for public API to close the client explicitly
8aae9db to
c32eef0
Compare
This commit adds mouse HID functionality, and provides a
context-manager for the whole NanoKVMClient, in a way that
a separate context manager is not necessary anymore.
This is backwards imcompatible, but it should be easy to switch
from:
```
async with ClientSession() as session:
client = NanoKVMClient("http://kvm-8b76.local/api/", session)
await client.authenticate("username", "password")
```
to:
```
async with NanoKVMClient("http://kvm-8b76.local/api/", session) as client:
await client.authenticate("username", "password")
```
c32eef0 to
81083aa
Compare
|
👋 :D |
|
Ah, sorry! I forgot to actually merge and release this 😅 |
This commit adds mouse HID functionality, and provides a
context-manager for the whole NanoKVMClient, in a way that
a separate context manager is not necessary anymore.
This is backwards imcompatible, but it should be easy to switch
from:
to:
This change provides the new following methods: