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(
{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,