From e78a2e3e416decf367b6320493c582ba3d83fd93 Mon Sep 17 00:00:00 2001 From: Arksine Date: Tue, 11 Aug 2020 20:43:20 -0400 Subject: [PATCH] gcode_apis: handle restart exceptions It is expected that the Klippy will disconnect when a restart request is sent. Handle those exceptions so they return an acknowledgement. Signed-off-by: Eric Callahan --- moonraker/plugins/gcode_apis.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/moonraker/plugins/gcode_apis.py b/moonraker/plugins/gcode_apis.py index bfd291e..4e5ecc0 100644 --- a/moonraker/plugins/gcode_apis.py +++ b/moonraker/plugins/gcode_apis.py @@ -58,10 +58,20 @@ class GCodeAPIs: return await self._send_gcode(script) async def gcode_restart(self, path, method, args): - return await self._send_gcode("RESTART") + return await self._do_restart("RESTART") async def gcode_firmware_restart(self, path, method, args): - return await self._send_gcode("FIRMWARE_RESTART") + return await self._do_restart("FIRMWARE_RESTART") + + async def _do_restart(self, gc): + try: + result = await self._send_gcode(gc) + except self.server.error as e: + if str(e) == "Klippy Disconnected": + result = "ok" + else: + raise + return result def load_plugin(config): return GCodeAPIs(config)