Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1.  
  2. import octoprint.plugin
  3.  
  4. import flask
  5.  
  6. class MySimpleApiPlugin(octoprint.plugin.SimpleApiPlugin):
  7.     def get_api_commands(self):
  8.         return dict(
  9.             command1=[],
  10.             command2=["some_parameter"],
  11.             command3=[],
  12.             command4=[]
  13.         )
  14.  
  15.     def on_api_command(self, command, data):
  16.         import flask
  17.         if command == "command1":
  18.             parameter = "unset"
  19.             if "parameter" in data:
  20.                 parameter = "set"
  21.             self._logger.info("command1 called, parameter is {parameter}".format(**locals()))
  22.         elif command == "command2":
  23.             self._logger.info("command2 called, some_parameter is {some_parameter}".format(**data))
  24.         elif command == "command3":
  25.             print "test"
  26.             return flask.jsonify(foo="bar")
  27.         elif command == "command4":
  28.            return make_response("testantwort", 200)
  29.  
  30.     def on_api_get(self, request):
  31.         return flask.jsonify(foo="bar")
  32.         #return make_response("testantwort", 200)
  33.  
  34. __plugin_implementation__ = MySimpleApiPlugin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement