From bc5044b1256249fc6c6c086a1efaf8487ccd7345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 14 Oct 2016 16:01:03 +0200 Subject: [PATCH] Fix target temperature propagation from comm layer When setting the tracked target temperature from a sent temperature command, the changes in tracked temperature were not propagated from the comm layer to registered callbacks. But since the standard printer also didn't make a copy of the mutable dict of tool temperatures, those were in fact updated even without propagation in the printer implementation when the values in the comm layer got updated, whereas the bed temperature - an immutable tupel - was not. Two wrongs sometimes do in fact make a right. In this case that led to target temperature changes on the tools immediately reflecting in printer.get_current_temperatures after the command was sent, but changes to the bed target taking until the next M105 response to propagate. Decoupling the data structures and adding propagation commands to the comm layer solves this issue. Fixes #1543 --- src/octoprint/printer/standard.py | 4 ++-- src/octoprint/util/comm.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 8281aad1..01299520 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -292,7 +292,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): def set_temperature(self, heater, value): if not PrinterInterface.valid_heater_regex.match(heater): - raise ValueError("heater must match \"tool[0-9]+\" or \"bed\": {heater}".format(type=heater)) + raise ValueError("heater must match \"tool[0-9]+\" or \"bed\": {heater}".format(heater=heater)) if not isinstance(value, (int, long, float)) or value < 0: raise ValueError("value must be a valid number >= 0: {value}".format(value=value)) @@ -915,7 +915,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._addLog(to_unicode(message, "utf-8", errors="replace")) def on_comm_temperature_update(self, temp, bedTemp): - self._addTemperatureData(temp, bedTemp) + self._addTemperatureData(copy.deepcopy(temp), copy.deepcopy(bedTemp)) def on_comm_state_change(self, state): """ diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 7b52046c..e5ccd98f 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2141,6 +2141,7 @@ class MachineCom(object): self._temp[toolNum] = (actual, target) else: self._temp[toolNum] = (None, target) + self._callback.on_comm_temperature_update(self._temp, self._bedTemp) except ValueError: pass @@ -2154,6 +2155,7 @@ class MachineCom(object): self._bedTemp = (actual, target) else: self._bedTemp = (None, target) + self._callback.on_comm_temperature_update(self._temp, self._bedTemp) except ValueError: pass