klippy_apis: update request handlers to accept WebRequest objects

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-11-09 07:01:38 -05:00
parent 27a17ed5a6
commit a260356d78
1 changed files with 10 additions and 8 deletions

View File

@ -4,6 +4,7 @@
# #
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
import utils import utils
from websockets import WebRequest
INFO_ENDPOINT = "info" INFO_ENDPOINT = "info"
ESTOP_ENDPOINT = "emergency_stop" ESTOP_ENDPOINT = "emergency_stop"
@ -36,28 +37,29 @@ class KlippyAPI:
self.server.register_endpoint( self.server.register_endpoint(
"/printer/firmware_restart", ['POST'], self._gcode_firmware_restart) "/printer/firmware_restart", ['POST'], self._gcode_firmware_restart)
async def _gcode_pause(self, path, method, args): async def _gcode_pause(self, web_request):
return await self.run_gcode("PAUSE") return await self.run_gcode("PAUSE")
async def _gcode_resume(self, path, method, args): async def _gcode_resume(self, web_request):
return await self.run_gcode("RESUME") return await self.run_gcode("RESUME")
async def _gcode_cancel(self, path, method, args): async def _gcode_cancel(self, web_request):
return await self.run_gcode("CANCEL_PRINT") return await self.run_gcode("CANCEL_PRINT")
async def _gcode_start_print(self, path, method, args): async def _gcode_start_print(self, web_request):
filename = args.get('filename') filename = web_request.get_str('filename')
return await self.start_print(filename) return await self.start_print(filename)
async def _gcode_restart(self, path, method, args): async def _gcode_restart(self, web_request):
return await self.do_restart("RESTART") return await self.do_restart("RESTART")
async def _gcode_firmware_restart(self, path, method, args): async def _gcode_firmware_restart(self, web_request):
return await self.do_restart("FIRMWARE_RESTART") return await self.do_restart("FIRMWARE_RESTART")
async def _send_klippy_request(self, method, params, default=Sentinel): async def _send_klippy_request(self, method, params, default=Sentinel):
try: try:
result = await self.server.make_request(method, params) result = await self.server.make_request(
WebRequest(method, params))
except self.server.error as e: except self.server.error as e:
if default == Sentinel: if default == Sentinel:
raise raise