Be RESTUful #169
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,
First thanks for your work on this plugin, it is awesome and I use it everyday !
I started to look at integrated it to Home-Assistant but it looks like the format of the API is not RESTful at all :(
Here is the format it should adopt to be compliant :
Create a endpoint /plugin/enclosure/outputs to replace /plugin/enclosure/getOutputStatus
Create /plugin/enclosure/outputs/{OUTPUT_ID} to replace /plugin/enclosure/setIO
=> When sending a GET request to this endpoint, it should send the status of the output
=> When sending a POST request to this enpoint, it should set the status out the output
The same applies to /plugin/enclosure/setEnclosureTempHum
Create /plugin/enclosure/temperature/{OUTPUT_ID}
POST will set the value
And so on with other endpoints :)
It would be cleaner and more standard, that will make it work with every RESTful clients natively.
It doesn't seem to be a difficult mod so I could make a pull request but I would like to be sure you agree with these changes :)
Thanks
EDIT : Using SimpleApiPlugin might even simplify the current API ;)
Hello @bistory
I have no problem with the proposed changes, the current implementation was actually someone's pull requested kind of hacked together, to use as API, the initial implementation was not "thought" to be used as an external API, I overlooked that big time...
If you want to work on it go for it! I can help with code review and testing.
Right now I don't have the time to stop and actually implement everything, but I don't have anything against the proposed changes.
I would also need a REST-Api for the temperature-readings of my DHT22s to impliment them to openHAB.
Thank you....
The API are not REST-ful but it is not really a problem.
You can get the whole plugin configuration from http://docs.octoprint.org/en/master/api/settings.html
And retrieve the updated informations from the websocket (/sockjs/websocket). The different messages look like the following:
{"plugin": {"data": {"rpi_output_neopixel": [{"color": "rgb(0,0,0)", "auto_shutdown": false, "index_id": 15, "auto_startup": false}], "rpi_output_pwm": [], "rpi_output_temp_hum_ctrl": [{"status": true, "auto_shutdown": true, "index_id": 16, "auto_startup": false}, {"status": false, "auto_shutdown": true, "index_id": 17, "auto_startup": false}], "rpi_output_regular": [{"status": 1, "auto_shutdown": true, "index_id": 1, "auto_startup": true}, {"status": false, "auto_shutdown": true, "index_id": 9, "auto_startup": true}, {"status": 1, "auto_shutdown": true, "index_id": 10, "auto_startup": true}]}, "plugin": "enclosure"}}
{"plugin": {"data": {"sensor_data": [{"index_id": 2, "temperature": 0.0, "humidity": 0.0}]}, "plugin": "enclosure"}}
{"plugin": {"data": {"set_temperature": [{"set_temperature": 124.0, "index_id": 16}, 124.0, {"set_temperature": 30.0, "index_id": 17}, 30.0]}, "plugin": "enclosure"}}
{"plugin": {"data": {"filament_sensor_status": []}, "plugin": "enclosure"}}
Indeed the other API from this plugins are all GET but you can execute all the actions you need without any problem, whatever happens ;)
Sry... can´t find any data here: (http://>IP</api/settings?apikey=>KEY<)
Temperature at the WEB-UI is showing up correct.
`
ok... something strange:
the second sensor is showing 24.7 ° at /api/settings
if i refresh the web-ui the data from /api/settings is shown first (0° and 24.7°) after a short time the correct temperature is appearing in the web-ui.
data in /api/settings is not changing.