Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 38 additions & 11 deletions octoprint_moonraker_connector/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,19 @@ class MoonrakerClient(JsonRpcClient):
HTTP_URL = "http://{host}:{port}"

GENERIC_HEATER_PREFIX = "heater_generic "
GENERIC_EXTRUDER_PREFIX = "extruder"
GENERIC_TEMPERATURE_FAN_PREFIX = "temperature_fan "
GENERIC_TEMPERATURE_PROBE_PREFIX = "temperature_probe "
GENERIC_TEMPERATURE_SENSOR_PREFIX = "temperature_sensor "
GENERIC_TMC_PREFIX = "tmc"
TMC_HAVE_TEMPERATURE = [
"tmc2240",
]
MACRO_PREFIX = "gcode_macro "

RELEVANT_PRINTER_OBJECTS = (
"configfile",
"display_status",
"extruder",
"gcode_move",
"heater_bed",
"idle_timeout",
Expand All @@ -315,7 +322,12 @@ class MoonrakerClient(JsonRpcClient):
lambda obj_list: [
x
for x in obj_list
if x.startswith(MoonrakerClient.GENERIC_HEATER_PREFIX)
if x.startswith(MoonrakerClient.GENERIC_EXTRUDER_PREFIX)
or x.startswith(MoonrakerClient.GENERIC_HEATER_PREFIX)
or x.startswith(MoonrakerClient.GENERIC_TEMPERATURE_FAN_PREFIX)
or x.startswith(MoonrakerClient.GENERIC_TEMPERATURE_PROBE_PREFIX)
or x.startswith(MoonrakerClient.GENERIC_TEMPERATURE_SENSOR_PREFIX)
or x.startswith(MoonrakerClient.GENERIC_TMC_PREFIX)
or x.startswith(MoonrakerClient.MACRO_PREFIX)
],
)
Expand Down Expand Up @@ -567,8 +579,13 @@ def on_printer_objects(future: Future) -> None:
self._heaters = [
obj
for obj in matched_objs
if obj in ("extruder", "heater_bed")
if obj in ("heater_bed")
or obj.startswith(self.GENERIC_EXTRUDER_PREFIX)
or obj.startswith(self.GENERIC_HEATER_PREFIX)
or obj.startswith(self.GENERIC_TEMPERATURE_FAN_PREFIX)
or obj.startswith(self.GENERIC_TEMPERATURE_PROBE_PREFIX)
or obj.startswith(self.GENERIC_TEMPERATURE_SENSOR_PREFIX)
or obj.startswith(self.GENERIC_TMC_PREFIX)
]

self.query_printer_objects(matched_objs)
Expand Down Expand Up @@ -615,8 +632,8 @@ def on_result(future: Future) -> None:
payload = result["status"]
self._process_query_result(payload)

except Exception:
self._logger.exception("Error while querying printer objects")
except Exception as e:
self._logger.exception(f"Error while querying printer objects: {e}")

params = {"objects": dict.fromkeys(objs)}
future = self.call_method("printer.objects.query", params=params)
Expand Down Expand Up @@ -1078,15 +1095,25 @@ def _update_temperatures(self, payload: dict[str, Any]) -> None:
if heater not in payload:
continue

name = (
heater[len(self.GENERIC_HEATER_PREFIX) :]
if heater.startswith(self.GENERIC_HEATER_PREFIX)
else heater
)
if heater.startswith(self.GENERIC_HEATER_PREFIX):
name = heater[len(self.GENERIC_HEATER_PREFIX) :]
elif heater.startswith(self.GENERIC_TEMPERATURE_FAN_PREFIX):
name = heater[len(self.GENERIC_TEMPERATURE_FAN_PREFIX) :]
elif heater.startswith(self.GENERIC_TEMPERATURE_PROBE_PREFIX):
name = heater[len(self.GENERIC_TEMPERATURE_PROBE_PREFIX) :]
elif heater.startswith(self.GENERIC_TEMPERATURE_SENSOR_PREFIX):
name = heater[len(self.GENERIC_TEMPERATURE_SENSOR_PREFIX) :]
elif heater.startswith(self.GENERIC_TMC_PREFIX):
name = heater[8:]
driver = heater[:7]
if driver not in self.TMC_HAVE_TEMPERATURE:
continue
else:
name = heater

data = self._current_temperatures.get(name, TemperatureDataPoint())
if "temperature" in payload[heater]:
data.actual = payload[heater]["temperature"]
data.actual = payload[heater]["temperature"] or 0
dirty_actual = True
if "target" in payload[heater]:
data.target = payload[heater]["target"]
Expand Down
22 changes: 15 additions & 7 deletions octoprint_moonraker_connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def connection_preconditions_met(cls, params):
host = params.get("host")
return host and resolve_host(host)

TEMPERATURE_LOOKUP = {"extruder": "tool0", "heater_bed": "bed", "chamber": "chamber"}
TEMPERATURE_LOOKUP = {"extruder": "tool0", "heater_bed": "bed", "chamber": "chamber", "Chamber": "chamber", "cavity": "chamber"}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -573,6 +573,14 @@ def on_moonraker_connected(self):
"apikey": self._apikey is not None,
},
)
extruder_count = self._profile["extruder"]["count"]
if extruder_count > 1:
for i in range(1, extruder_count):
if f"extruder{i}" not in self.TEMPERATURE_LOOKUP:
self.TEMPERATURE_LOOKUP[f"extruder{i}"] = f"tool{i}"
for heater, data in self._client.current_temperatures.items():
if heater not in self.TEMPERATURE_LOOKUP:
self.TEMPERATURE_LOOKUP[heater] = heater
self._listener.on_printer_files_available(True)
self.refresh_printer_files(recursive=True)

Expand All @@ -598,12 +606,12 @@ def on_moonraker_server_info(self, server_info):
def on_moonraker_temperature_update(
self, data: dict[str, TemperatureDataPoint]
) -> None:
self._listener.on_printer_temperature_update(
{
self.TEMPERATURE_LOOKUP.get(key): (value.actual, value.target)
for key, value in data.items()
}
)
mapped_data = {}
for key, value in data.items():
new_key = self.TEMPERATURE_LOOKUP.get(key)
if new_key is not None:
mapped_data[new_key] = (value.actual, value.target)
self._listener.on_printer_temperature_update(mapped_data)

def on_moonraker_gcode_log(self, *lines: str) -> None:
self._listener.on_printer_logs(*lines)
Expand Down