-
Notifications
You must be signed in to change notification settings - Fork 5
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
Support both Digest and API key authentication #25
Conversation
@@ -0,0 +1,13 @@ | |||
{ pkgs ? import <nixpkgs> {} }: |
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.
We should not include nix configuration in the package.
If the SL1S returns API version 0.1 and uses a different auth scheme, it's not the right version of the prusalink API? What other things are incompatible? Are they going to upgrade SL1S for the new prusalink? |
The SL1S is not incompatible with the old scheme per se - but Prusa officially recommends Digest over using API keys. At least such a warning is displayed on the SL1S. It seemed sensible to me to support both methods in I can't yet say for certain why API version 0.1 is returned on my printer. The latest updates are installed on it already and the API calls made by |
Should we start with opening an issue for the version number on https://github.com/prusa3d/Prusa-Firmware-SL1 for that? That sounds like a bug.
What you're saying is that it does support API keys? |
Possibly! I’ll check if it’s a known issue at all.
Yup, the SL1S supports both. |
In that case I don't see a reason to change from aiohttp to httpx just to get digest working. They only support API keys on the mini so it doesn't look like it's the recommended way. |
On the Prusa SL1S, Digest is in fact explicitly recommended as I’ve stated above. With that in mind, do you still wish to stop moving forward with this? |
@balloob : we need digest auth C an this be re-opened ? |
Maybe I am missing something, but how do you know that is the fix for your issue? |
Please read:
The plugin is not working since PrusaLink 0.7.0rc2.
What I am unsure about is that a curl call works:
But the HA plugin is not able to communicate through API. I think this is because of this check: https://github.com/home-assistant/core/blob/dev/homeassistant/components/prusalink/config_flow.py#L49 For the 2 latest RC version, Prusalink returns: {
"api": "0.9.0-legacy",
"server": "0.7.0rc3",
"original": "PrusaLink I3MK3S",
"text": "PrusaLink 0.7.0rc3",
"firmware": "3.11.0-4955",
"sdk": "0.7.0rc3",
"capabilities": {
"upload-by-put": true
},
"hostname": "PrusaLink"
} |
I also get an interesting API version ( There exists a check in In both of our cases, the error seems to be raised there. |
I agree. I saw the same thing. Let's continue the discussion here then: home-assistant/core#86230 |
This post seems like an official statement that API key is deprecated and this PR is ok to move forward: https://forum.prusa3d.com/forum/postid/634572/ |
|
||
This fork adds support for Digest authentication - the method Prusa recommends for their resin printers (SL1, SL1S). |
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.
This fork adds support for Digest authentication - the method Prusa recommends for their resin printers (SL1, SL1S). |
@@ -94,53 +74,65 @@ async def pause_job(self) -> None: | |||
async def get_version(self) -> VersionInfo: | |||
"""Get the version.""" | |||
async with self.request("GET", "api/version") as response: | |||
return await response.json() | |||
return response.json() |
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.
This is very wrong, you're doing I/O in the event loop and hating Home Assistant. Use the async version of httpx.
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.
or is httpx reading the whole response right away?
from .const import API_KEY_AUTH, DIGEST_AUTH | ||
|
||
|
||
class VersionInfo(TypedDict): |
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.
Since there are multiple versions of the API that we all want to support, we should probably include a version number in the type names.
|
||
files: list[FileInfo] | ||
|
||
|
||
class PrusaLink: |
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.
Do we need to split this into multiple classes, one for each version of the API? We can put the request function into a single base class.
|
||
files: list[FileInfo] | ||
|
||
|
||
class PrusaLink: | ||
"""Wrapper for the Prusalink API. | ||
|
||
Data format can be found here: |
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.
Update this doc string to also include other APIs
Superseded by #63 |
I would like to integrate my Prusa SL1S into Home Assistant. Prusa supports both Digest and API key authentication but recommends Digest. Thus I've updated both
pyprusalink
and the corresponding Home Assistant component inhome-assistant/core
to allow for this.The API change is breaking.
I intend to keep working on this for my local setup, primarily adding sensors that are useful for resin printers. Maybe you're interested in upstreaming. If so, I'll also open a PR against
home-assistant/core
.I currently know of one open problem I could use help with if you'd like:
2
and refuses to connect to the printer otherwise. But my SL1S actually returns the following from/api/version
:Do you have any idea why that is? Is your printer running
"api": "2.0"
?