Turn on_connection_changed to coroutine

Further compresses the connect
This commit is contained in:
atse 2023-07-18 10:28:56 +08:00
parent 82438ee4a5
commit b4a5e90f2e
1 changed files with 7 additions and 7 deletions

View File

@ -93,7 +93,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.port_set_spin.setValue(int(args.PORT)) self.port_set_spin.setValue(int(args.PORT))
self.connect_btn.click() self.connect_btn.click()
def _on_connection_changed(self, result): async def _on_connection_changed(self, result):
self.graph_group.setEnabled(result) self.graph_group.setEnabled(result)
self.fan_group.setEnabled(result) self.fan_group.setEnabled(result)
self.report_group.setEnabled(result) self.report_group.setEnabled(result)
@ -105,6 +105,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.status_lbl.setText("Disconnected") self.status_lbl.setText("Disconnected")
self.fan_pwm_warning.setPixmap(QtGui.QPixmap()) self.fan_pwm_warning.setPixmap(QtGui.QPixmap())
self.fan_pwm_warning.setToolTip("") self.fan_pwm_warning.setToolTip("")
else:
self._status(await self.tec_client.hw_rev())
self.fan_update(await self.tec_client.fan())
def _set_fan_pwm_warning(self): def _set_fan_pwm_warning(self):
if self.fan_power_slider.value() != 100: if self.fan_power_slider.value() != 100:
@ -174,21 +177,18 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
except asyncio.CancelledError: except asyncio.CancelledError:
return return
self._on_connection_changed(True) await self._on_connection_changed(True)
self._status(await self.tec_client.hw_rev())
self.fan_update(await self.tec_client.fan())
self.client_watcher.start_watching() self.client_watcher.start_watching()
else: else:
self.client_watcher.stop_watching() self.client_watcher.stop_watching()
await self.tec_client.disconnect() await self.tec_client.disconnect()
self._on_connection_changed(False) await self._on_connection_changed(False)
except (OSError, TimeoutError) as e: except (OSError, TimeoutError) as e:
logging.error(f"Failed communicating to {ip}:{port}: {e}") logging.error(f"Failed communicating to {ip}:{port}: {e}")
await self.tec_client.disconnect() await self.tec_client.disconnect()
self._on_connection_changed(False) await self._on_connection_changed(False)
async def coro_main(): async def coro_main():