Change name of tec_client

This commit is contained in:
atse 2023-07-31 16:36:48 +08:00 committed by Tse Kwok Yan
parent 17ea0e252a
commit 6a902e5f9d
1 changed files with 21 additions and 21 deletions

View File

@ -171,8 +171,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.hw_rev_data = None
self.tec_client = Client()
self.client_watcher = ClientWatcher(self, self.tec_client, self.report_refresh_spin.value())
self.client = Client()
self.client_watcher = ClientWatcher(self, self.client, self.report_refresh_spin.value())
self.client_watcher.fan_update.connect(self.fan_update)
self.client_watcher.report_update.connect(self.plot)
self.client_watcher.report_update.connect(self.update_report)
@ -312,7 +312,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
@asyncSlot(bool)
async def reset_thermostat(_):
await self._on_connection_changed(False)
await self.tec_client.reset()
await self.client.reset()
await asyncio.sleep(0.1) # Wait for the reset to start
self.connect_btn.click() # Reconnect
@ -425,8 +425,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.connect_btn.setText("Disconnect" if result else "Connect")
if result:
self.client_watcher.start_watching()
self._status(await self.tec_client.hw_rev())
self.fan_update(await self.tec_client.fan())
self._status(await self.client.hw_rev())
self.fan_update(await self.client.fan())
else:
self.status_lbl.setText("Disconnected")
self.fan_pwm_warning.setPixmap(QtGui.QPixmap())
@ -466,24 +466,24 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
@asyncSlot(int)
async def fan_set(self, value):
if not self.tec_client.is_connected():
if not self.client.is_connected():
return
if self.fan_auto_box.isChecked():
with QSignalBlocker(self.fan_auto_box):
self.fan_auto_box.setChecked(False)
await self.tec_client.set_param("fan", value)
await self.client.set_param("fan", value)
if not self.hw_rev_data["settings"]["fan_pwm_recommended"]:
self._set_fan_pwm_warning()
@asyncSlot(int)
async def fan_auto_set(self, enabled):
if not self.tec_client.is_connected():
if not self.client.is_connected():
return
if enabled:
await self.tec_client.set_param("fan", "auto")
self.fan_update(await self.tec_client.fan())
await self.client.set_param("fan", "auto")
self.fan_update(await self.client.fan())
else:
await self.tec_client.set_param("fan", self.fan_power_slider.value())
await self.client.set_param("fan", self.fan_power_slider.value())
@asyncSlot(int)
async def on_report_box_stateChanged(self, enabled):
@ -491,48 +491,48 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
if enabled:
self.report_mode_task = asyncio.create_task(self.report_mode())
else:
self.tec_client.stop_report_mode()
self.client.stop_report_mode()
await self.report_mode_task
self.report_mode_task = None
async def report_mode(self):
async for report in self.tec_client.report_mode():
async for report in self.client.report_mode():
self.client_watcher.report_update.emit(report)
async def stop_report_mode(self):
if self.report_mode_task is not None:
self.tec_client.stop_report_mode()
self.client.stop_report_mode()
await self.report_mode_task
self.report_mode_task = None
@asyncClose
async def closeEvent(self, event):
await self._on_connection_changed(False)
await self.tec_client.disconnect()
await self.client.disconnect()
@asyncSlot()
async def on_connect_btn_clicked(self):
ip, port = self.host_set_line.text(), self.port_set_spin.value()
try:
if not (self.tec_client.is_connecting() or self.tec_client.is_connected()):
if not (self.client.is_connecting() or self.client.is_connected()):
self.status_lbl.setText("Connecting...")
self.connect_btn.setText("Stop")
self.host_set_line.setEnabled(False)
self.port_set_spin.setEnabled(False)
try:
await self.tec_client.connect(host=ip, port=port, timeout=30)
await self.client.connect(host=ip, port=port, timeout=30)
except StoppedConnecting:
return
await self._on_connection_changed(True)
else:
await self._on_connection_changed(False)
await self.tec_client.disconnect()
await self.client.disconnect()
except (OSError, TimeoutError, asyncio.TimeoutError) as e: # TODO: Remove asyncio.TimeoutError in Python 3.11
logging.error(f"Failed communicating to {ip}:{port}: {e}")
await self._on_connection_changed(False)
await self.tec_client.disconnect()
await self.client.disconnect()
@pyqtSlot(list)
def plot(self, report):
@ -550,7 +550,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
for param, change, data in changes:
if param.name() == 'Temperature PID' and not data:
ch = param.opts["payload"]
await self.tec_client.set_param('pwm', ch, 'i_set', params[ch].child('Constant Current').value())
await self.client.set_param('pwm', ch, 'i_set', params[ch].child('Constant Current').value())
line = getattr(self, f'ch{ch}_t_line')
line.setVisible(False)
elif param.opts.get("commands", None) is not None:
@ -558,7 +558,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
getattr(self, f'ch{param.opts["payload"]}_t_line').setVisible(True)
elif param.name() == 'Set Temperature':
getattr(self, f'ch{param.opts["payload"]}_t_line').setValue(data)
await asyncio.gather(*[self.tec_client._command(x.format(value=data)) for x in param.opts["commands"]])
await asyncio.gather(*[self.client._command(x.format(value=data)) for x in param.opts["commands"]])
def _set_param_tree(self):
for i, tree in enumerate((self.ch0_tree, self.ch1_tree)):