Don't use payload to get channel

Use parent param instead
This commit is contained in:
atse 2023-08-04 17:46:38 +08:00
parent 6f40adb19d
commit 82c3576603

View File

@ -26,10 +26,10 @@ class CommandsParameter(Parameter):
THERMOSTAT_PARAMETERS = [[
{'name': 'Constant Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (-3, 3), 'siPrefix': True,
'suffix': 'A', 'commands': [f'pwm {ch} i_set {{value}}']},
{'name': 'Temperature PID', 'type': 'bool', 'value': False, 'commands': [f'pwm {ch} pid'], 'payload': ch,
{'name': 'Temperature PID', 'type': 'bool', 'value': False, 'commands': [f'pwm {ch} pid'],
'children': [
{'name': 'Set Temperature', 'type': 'float', 'value': 25, 'step': 0.1, 'limits': (-273, 300), 'siPrefix': True,
'suffix': '°C', 'commands': [f'pid {ch} target {{value}}'], 'payload': ch},
'suffix': '°C', 'commands': [f'pid {ch} target {{value}}']},
]},
{'name': 'Output Config', 'expanded': False, 'type': 'group', 'children': [
{'name': 'Max Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 3), 'siPrefix': True, 'prefix': '±',
@ -65,8 +65,8 @@ THERMOSTAT_PARAMETERS = [[
params = [
CommandsParameter.create(name='Thermostat Params 0', type='group', children=THERMOSTAT_PARAMETERS[0]),
CommandsParameter.create(name='Thermostat Params 1', type='group', children=THERMOSTAT_PARAMETERS[1]),
CommandsParameter.create(name='Thermostat Params 0', type='group', value=0, children=THERMOSTAT_PARAMETERS[0]),
CommandsParameter.create(name='Thermostat Params 1', type='group', value=1, children=THERMOSTAT_PARAMETERS[1]),
]
@ -602,10 +602,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
async def send_command(self, param, changes):
for inner_param, change, data in changes:
if inner_param.opts.get("commands", None) is not None:
ch = param.value()
match inner_param.name():
case 'Temperature PID':
pid_enabled = data
ch = inner_param.opts['payload']
getattr(self, f'ch{ch}_t_line').setVisible(pid_enabled)
if pid_enabled:
getattr(self, f'ch{ch}_t_line').setValue(inner_param.child('Set Temperature').value())
@ -613,7 +613,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
await self.client.set_param('pwm', ch, 'i_set', param.child('Constant Current').value())
return
case 'Set Temperature':
ch = inner_param.opts['payload']
getattr(self, f'ch{ch}_t_line').setValue(data)
await asyncio.gather(*[self.client._command(x.format(value=data)) for x in inner_param.opts["commands"]])