Use thermotat_data_model for everything

This commit is contained in:
atse 2024-07-08 12:01:37 +08:00
parent e129998629
commit 2c019b8208
3 changed files with 16 additions and 12 deletions

View File

@ -4,10 +4,11 @@ from autotune import PIDAutotuneState, PIDAutotune
class PIDAutoTuner(QObject): class PIDAutoTuner(QObject):
def __init__(self, parent, client, num_of_channel): def __init__(self, parent, client, thermostat, num_of_channel):
super().__init__() super().__init__()
self._client = client self._client = client
self._thermostat = thermostat
self.autotuners = [PIDAutotune(25) for _ in range(num_of_channel)] self.autotuners = [PIDAutotune(25) for _ in range(num_of_channel)]
self.target_temp = [20.0 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)] 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): async def stop_pid_from_running(self, ch):
self.autotuners[ch].setOff() 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) @asyncSlot(list)
async def tick(self, report): async def tick(self, report):
@ -56,21 +57,21 @@ class PIDAutoTuner(QObject):
self.autotuners[ch].run( self.autotuners[ch].run(
channel_report["temperature"], channel_report["time"] channel_report["temperature"], channel_report["time"]
) )
await self._client.set_param( await self.thermostat.set_param(
"pwm", ch, "i_set", self.autotuners[ch].output() "pwm", ch, "i_set", self.autotuners[ch].output()
) )
case PIDAutotuneState.STATE_SUCCEEDED: case PIDAutotuneState.STATE_SUCCEEDED:
kp, ki, kd = self.autotuners[ch].get_tec_pid() kp, ki, kd = self.autotuners[ch].get_tec_pid()
self.autotuners[ch].setOff() self.autotuners[ch].setOff()
await self._client.set_param("pid", ch, "kp", kp) await self.thermostat.set_param("pid", ch, "kp", kp)
await self._client.set_param("pid", ch, "ki", ki) await self.thermostat.set_param("pid", ch, "ki", ki)
await self._client.set_param("pid", ch, "kd", kd) await self.thermostat.set_param("pid", ch, "kd", kd)
await self._client.set_param("pwm", ch, "pid") 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] "pid", ch, "target", self.target_temp[ch]
) )
case PIDAutotuneState.STATE_FAILED: case PIDAutotuneState.STATE_FAILED:
self.autotuners[ch].setOff() self.autotuners[ch].setOff()
await self._client.set_param("pwm", ch, "i_set", 0) await self.thermostat.set_param("pwm", ch, "i_set", 0)

View File

@ -132,3 +132,6 @@ class Thermostat(QObject, metaclass=PropertyMeta):
async def get_fan(self): async def get_fan(self):
return await self._client.get_fan() return await self._client.get_fan()
async def set_param(self, topic, channel, field="", value=""):
await self._client.set_param(topic, channel, field, value)

View File

@ -85,7 +85,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.thermostat.connection_error.connect(handle_connection_error) 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): def get_ctrl_panel_config(args):
with open(args.param_tree, "r") as f: with open(args.param_tree, "r") as f:
@ -295,7 +295,7 @@ class MainWindow(QtWidgets.QMainWindow):
else: else:
set_param_args = (*thermostat_param, data) set_param_args = (*thermostat_param, data)
param.child(*param.childPath(inner_param)).setOpts(lock=True) 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) param.child(*param.childPath(inner_param)).setOpts(lock=False)
if inner_param.opts.get("pid_autotune", None) is not None: 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 is not None:
if activater[1] == "ch": if activater[1] == "ch":
activater[1] = ch activater[1] = ch
await self.client.set_param(*activater) await self.thermostat.set_param(*activater)
@asyncSlot() @asyncSlot()
async def pid_auto_tune_request(self, ch=0): async def pid_auto_tune_request(self, ch=0):