Support getting the PSU state with a GET request #141
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do and why is it necessary?
According to common practices GET is used
to retrieve resource representation/information only
. This PR enables the plugin to respond to get requests to its API-endpoint with the current PSU state.How was it tested? How can it be tested by the reviewer?
I hot-patched the installed plugin on my octoprint instance with the newly added function. Afterwards I used curl to fetch the new endpoint:
For reviewers I suggest to do the same or alternatively point pip to install from my branch.
Any background context you want to provide?
My main motivation was to get the PSU control available in my home-assistant instance. For this I wanted to use the RESTful Switch component. This component is implemented as such that it retrieves the status over GET and sends updates over POST (following the best-practices linked above). To quote: "The switch can get the state via GET and set the state via POST on a given REST resource."
Further notes
I implemented this feature by calling the original implementation of this. This allows backwards compatibility and makes sure the same access restrictions are in place. Technically speaking I think that the "getPSUState"-POST-request should be removed but this is not a decision I wanted to take (especially since it might break existing setups).