send_command: Switch to thermostat:set_param

Use a `dict` to map values to thermostat parameters, which correspond to
the `set_param` parameters in the pytec client. New tag
"thermostat:set_param" used in JSON.
This commit is contained in:
atse 2024-08-14 13:13:43 +08:00
parent 46923ebdca
commit 72bd0cde7f
2 changed files with 65 additions and 78 deletions

View File

@ -46,11 +46,10 @@
"triggerOnShow":true,
"decimals":6,
"suffix":"mA",
"param":[
"pwm",
"ch",
"i_set"
],
"thermostat:set_param":{
"topic":"pwm",
"field":"i_set"
},
"lock":false
},
{
@ -63,11 +62,10 @@
300
],
"format":"{value:.4f} °C",
"param":[
"pid",
"ch",
"target"
],
"thermostat:set_param":{
"topic":"pid",
"field":"target"
},
"lock":false
}
]
@ -88,11 +86,10 @@
2000
],
"suffix":"mA",
"param":[
"pwm",
"ch",
"max_i_pos"
],
"thermostat:set_param":{
"topic":"pwm",
"field":"max_i_pos"
},
"lock":false
},
{
@ -106,11 +103,10 @@
2000
],
"suffix":"mA",
"param":[
"pwm",
"ch",
"max_i_neg"
],
"thermostat:set_param":{
"topic":"pwm",
"field":"max_i_neg"
},
"lock":false
},
{
@ -124,11 +120,10 @@
],
"siPrefix":true,
"suffix":"V",
"param":[
"pwm",
"ch",
"max_v"
],
"thermostat:set_param":{
"topic":"pwm",
"field":"max_v"
},
"lock":false
}
]
@ -150,11 +145,10 @@
100
],
"format":"{value:.4f} °C",
"param":[
"s-h",
"ch",
"t0"
],
"thermostat:set_param":{
"topic":"s-h",
"field":"t0"
},
"lock":false
},
{
@ -164,11 +158,10 @@
"step":1,
"siPrefix":true,
"suffix":"Ω",
"param":[
"s-h",
"ch",
"r0"
],
"thermostat:set_param":{
"topic":"s-h",
"field":"r0"
},
"lock":false
},
{
@ -178,22 +171,20 @@
"step":1,
"suffix":"K",
"decimals":4,
"param":[
"s-h",
"ch",
"b"
],
"thermostat:set_param":{
"topic":"s-h",
"field":"b"
},
"lock":false
},
{
"name":"Postfilter Rate",
"type":"list",
"value":16.67,
"param":[
"postfilter",
"ch",
"rate"
],
"thermostat:set_param":{
"topic":"postfilter",
"field":"rate"
},
"limits":{
"Off":null,
"16.67 Hz":16.67,
@ -215,11 +206,10 @@
"type":"float",
"step":0.1,
"suffix":"",
"param":[
"pid",
"ch",
"kp"
],
"thermostat:set_param":{
"topic":"pid",
"field":"kp"
},
"lock":false
},
{
@ -227,11 +217,10 @@
"type":"float",
"step":0.1,
"suffix":"Hz",
"param":[
"pid",
"ch",
"ki"
],
"thermostat:set_param":{
"topic":"pid",
"field":"ki"
},
"lock":false
},
{
@ -239,11 +228,10 @@
"type":"float",
"step":0.1,
"suffix":"s",
"param":[
"pid",
"ch",
"kd"
],
"thermostat:set_param":{
"topic":"pid",
"field":"kd"
},
"lock":false
},
{
@ -261,11 +249,10 @@
],
"decimals":6,
"suffix":"mA",
"param":[
"pid",
"ch",
"output_min"
],
"thermostat:set_param":{
"topic":"pid",
"field":"output_min"
},
"lock":false
},
{
@ -278,11 +265,10 @@
],
"decimals":6,
"suffix":"mA",
"param":[
"pid",
"ch",
"output_max"
],
"thermostat:set_param":{
"topic":"pid",
"field":"output_max"
},
"lock":false
}
]

View File

@ -267,20 +267,21 @@ class MainWindow(QtWidgets.QMainWindow):
for inner_param, change, data in changes:
if change == "value":
new_value = data
if "param" in inner_param.opts:
if "thermostat:set_param" in inner_param.opts:
if inner_param.opts.get("suffix", None) == "mA":
new_value /= 1000 # Given in mA
thermostat_param = inner_param.opts["param"]
if thermostat_param[1] == "ch":
thermostat_param[1] = ch
thermostat_param = inner_param.opts["thermostat:set_param"]
if inner_param.name() == "Postfilter Rate" and new_value is None:
set_param_args = (*thermostat_param[:2], "off")
else:
set_param_args = (*thermostat_param, new_value)
thermostat_param = thermostat_param.copy()
thermostat_param["field"] = "off"
new_value = ""
inner_param.setOpts(lock=True)
await self.client.set_param(*set_param_args)
await self.client.set_param(
channel=ch, value=new_value, **thermostat_param
)
inner_param.setOpts(lock=False)
if "pid_autotune" in inner_param.opts: