From d108334c37f8ed7e7566e19e49b58503f289896a Mon Sep 17 00:00:00 2001 From: Arksine Date: Sat, 6 Mar 2021 06:26:38 -0500 Subject: [PATCH] octoprint_compat: "/api/printer" bugfix Only report extruder and bed temperatures. Use dict "get()" methods to make sure that the fields are available. Signed-off-by: Eric Callahan --- moonraker/plugins/octoprint_compat.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/moonraker/plugins/octoprint_compat.py b/moonraker/plugins/octoprint_compat.py index e5bde53..f45cd30 100644 --- a/moonraker/plugins/octoprint_compat.py +++ b/moonraker/plugins/octoprint_compat.py @@ -106,6 +106,8 @@ class OctoprintCompat: result = await self.klippy_apis.query_objects( {heater: None for heater in self.heaters}) for heater in self.heaters: + if heater not in result: + continue data = result[heater] name = 'bed' if heater.startswith('extruder'): @@ -114,11 +116,12 @@ class OctoprintCompat: except ValueError: tool_no = 0 name = f'tool{tool_no}' - + elif heater != "heater_bed": + continue temps[name] = { - 'actual': int(data['temperature'] * 100.0) / 100.0, + 'actual': round(data.get('temperature', 0.), 2), 'offset': 0, - 'target': data['target'], + 'target': data.get('target', 0.), } return temps @@ -202,7 +205,7 @@ class OctoprintCompat: """ return { 'job': { - 'file': {'name': None,}, + 'file': {'name': None}, 'estimatedPrintTime': None, 'filament': {'length': None}, 'user': None, @@ -247,7 +250,7 @@ class OctoprintCompat: for command in commands: logging.info(f'Executing GCode: {command}') try: - await self.klippy_apis.run_gcode(command) + await self.klippy_apis.run_gcode(command) except self.server.error: msg = f"Error executing GCode {command}" logging.exception(msg)