diff --git a/pytec/pytec/gui/model/pid_autotuner.py b/pytec/pytec/gui/model/pid_autotuner.py index f9104ad..676d88f 100644 --- a/pytec/pytec/gui/model/pid_autotuner.py +++ b/pytec/pytec/gui/model/pid_autotuner.py @@ -4,10 +4,11 @@ from autotune import PIDAutotuneState, PIDAutotune class PIDAutoTuner(QObject): - def __init__(self, parent, client, num_of_channel): + def __init__(self, parent, client, thermostat, num_of_channel): super().__init__() self._client = client + self._thermostat = thermostat self.autotuners = [PIDAutotune(25) for _ in range(num_of_channel)] self.target_temp = [20.0 for _ in range(num_of_channel)] self.test_current = [1.0 for _ in range(num_of_channel)] @@ -37,7 +38,7 @@ class PIDAutoTuner(QObject): async def stop_pid_from_running(self, ch): self.autotuners[ch].setOff() - await self._client.set_param("pwm", ch, "i_set", 0) + await self.thermostat.set_param("pwm", ch, "i_set", 0) @asyncSlot(list) async def tick(self, report): @@ -56,21 +57,21 @@ class PIDAutoTuner(QObject): self.autotuners[ch].run( channel_report["temperature"], channel_report["time"] ) - await self._client.set_param( + await self.thermostat.set_param( "pwm", ch, "i_set", self.autotuners[ch].output() ) case PIDAutotuneState.STATE_SUCCEEDED: kp, ki, kd = self.autotuners[ch].get_tec_pid() self.autotuners[ch].setOff() - await self._client.set_param("pid", ch, "kp", kp) - await self._client.set_param("pid", ch, "ki", ki) - await self._client.set_param("pid", ch, "kd", kd) - await self._client.set_param("pwm", ch, "pid") + await self.thermostat.set_param("pid", ch, "kp", kp) + await self.thermostat.set_param("pid", ch, "ki", ki) + await self.thermostat.set_param("pid", ch, "kd", kd) + await self.thermostat.set_param("pwm", ch, "pid") - await self._client.set_param( + await self.thermostat.set_param( "pid", ch, "target", self.target_temp[ch] ) case PIDAutotuneState.STATE_FAILED: self.autotuners[ch].setOff() - await self._client.set_param("pwm", ch, "i_set", 0) + await self.thermostat.set_param("pwm", ch, "i_set", 0) diff --git a/pytec/pytec/gui/model/thermostat.py b/pytec/pytec/gui/model/thermostat.py index 8fc123d..d6e6a8d 100644 --- a/pytec/pytec/gui/model/thermostat.py +++ b/pytec/pytec/gui/model/thermostat.py @@ -132,3 +132,6 @@ class Thermostat(QObject, metaclass=PropertyMeta): async def get_fan(self): return await self._client.get_fan() + + async def set_param(self, topic, channel, field="", value=""): + await self._client.set_param(topic, channel, field, value) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 0cf202d..4c59f39 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -85,7 +85,7 @@ class MainWindow(QtWidgets.QMainWindow): self.thermostat.connection_error.connect(handle_connection_error) - self.autotuners = PIDAutoTuner(self, self.client, 2) + self.autotuners = PIDAutoTuner(self, self.client, self.thermostat, 2) def get_ctrl_panel_config(args): with open(args.param_tree, "r") as f: @@ -295,7 +295,7 @@ class MainWindow(QtWidgets.QMainWindow): else: set_param_args = (*thermostat_param, data) param.child(*param.childPath(inner_param)).setOpts(lock=True) - await self.client.set_param(*set_param_args) + await self.thermostat.set_param(*set_param_args) param.child(*param.childPath(inner_param)).setOpts(lock=False) if inner_param.opts.get("pid_autotune", None) is not None: @@ -313,7 +313,7 @@ class MainWindow(QtWidgets.QMainWindow): if activater is not None: if activater[1] == "ch": activater[1] = ch - await self.client.set_param(*activater) + await self.thermostat.set_param(*activater) @asyncSlot() async def pid_auto_tune_request(self, ch=0):