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 <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-03-06 06:26:38 -05:00
parent 13ccdb4df1
commit d108334c37
1 changed files with 8 additions and 5 deletions

View File

@ -106,6 +106,8 @@ class OctoprintCompat:
result = await self.klippy_apis.query_objects( result = await self.klippy_apis.query_objects(
{heater: None for heater in self.heaters}) {heater: None for heater in self.heaters})
for heater in self.heaters: for heater in self.heaters:
if heater not in result:
continue
data = result[heater] data = result[heater]
name = 'bed' name = 'bed'
if heater.startswith('extruder'): if heater.startswith('extruder'):
@ -114,11 +116,12 @@ class OctoprintCompat:
except ValueError: except ValueError:
tool_no = 0 tool_no = 0
name = f'tool{tool_no}' name = f'tool{tool_no}'
elif heater != "heater_bed":
continue
temps[name] = { temps[name] = {
'actual': int(data['temperature'] * 100.0) / 100.0, 'actual': round(data.get('temperature', 0.), 2),
'offset': 0, 'offset': 0,
'target': data['target'], 'target': data.get('target', 0.),
} }
return temps return temps
@ -202,7 +205,7 @@ class OctoprintCompat:
""" """
return { return {
'job': { 'job': {
'file': {'name': None,}, 'file': {'name': None},
'estimatedPrintTime': None, 'estimatedPrintTime': None,
'filament': {'length': None}, 'filament': {'length': None},
'user': None, 'user': None,
@ -247,7 +250,7 @@ class OctoprintCompat:
for command in commands: for command in commands:
logging.info(f'Executing GCode: {command}') logging.info(f'Executing GCode: {command}')
try: try:
await self.klippy_apis.run_gcode(command) await self.klippy_apis.run_gcode(command)
except self.server.error: except self.server.error:
msg = f"Error executing GCode {command}" msg = f"Error executing GCode {command}"
logging.exception(msg) logging.exception(msg)