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

View File

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