diff --git a/pytec/pytec/gui/model/pid_autotuner.py b/pytec/pytec/gui/model/pid_autotuner.py index 22837cd..999e89e 100644 --- a/pytec/pytec/gui/model/pid_autotuner.py +++ b/pytec/pytec/gui/model/pid_autotuner.py @@ -30,6 +30,19 @@ class PIDAutoTuner(QObject): def get_state(self, ch): return self.autotuners[ch].state() + @asyncSlot() + async def pid_auto_tune_request(self, ch): + match self.get_state(ch): + case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED: + self.load_params_and_set_ready(ch) + + case ( + PIDAutotuneState.STATE_READY + | PIDAutotuneState.STATE_RELAY_STEP_UP + | PIDAutotuneState.STATE_RELAY_STEP_DOWN + ): + await self.stop_pid_from_running(ch) + def load_params_and_set_ready(self, ch): self.autotuners[ch].setParam( self.target_temp[ch], diff --git a/pytec/pytec/gui/view/ctrl_panel.py b/pytec/pytec/gui/view/ctrl_panel.py index 2ed48f2..d815def 100644 --- a/pytec/pytec/gui/view/ctrl_panel.py +++ b/pytec/pytec/gui/view/ctrl_panel.py @@ -94,7 +94,7 @@ class CtrlPanel(QObject): ) self.params[i].child( "PID Config", "PID Auto Tune", "Run" - ).sigActivated.connect(partial(self.pid_auto_tune_request, i)) + ).sigActivated.connect(partial(self.autotuners.pid_auto_tune_request, i)) self.thermostat.pid_update.connect(self.update_pid) self.thermostat.report_update.connect(self.update_report) @@ -303,17 +303,3 @@ class CtrlPanel(QObject): f"Channel {ch} settings has been saved to flash.\n" "It will be loaded on Thermostat reset, or when settings are explicitly loaded.", ) - - @asyncSlot() - async def pid_auto_tune_request(self, ch=0): - match self.autotuners.get_state(ch): - case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED: - self.autotuners.load_params_and_set_ready(ch) - - case ( - PIDAutotuneState.STATE_READY - | PIDAutotuneState.STATE_RELAY_STEP_UP - | PIDAutotuneState.STATE_RELAY_STEP_DOWN - ): - await self.autotuners.stop_pid_from_running(ch) -