From 2b02ea334a7d4cf91a3ae4ca03cfdd6094816473 Mon Sep 17 00:00:00 2001 From: atse Date: Mon, 9 Sep 2024 18:29:24 +0800 Subject: [PATCH] No need to create a new task for waiting --- pytec/tec_qt.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 3444ace..10172e9 100755 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -193,14 +193,12 @@ class MainWindow(QtWidgets.QMainWindow): async def on_connect_btn_clicked(self): match self._thermostat.connection_state: case ThermostatConnectionState.DISCONNECTED: - self._connecting_task = asyncio.create_task( - self._thermostat.start_session( - host=self.connection_details_menu.host_set_line.text(), - port=self.connection_details_menu.port_set_spin.value(), - ) - ) + self._connecting_task = asyncio.current_task() self._thermostat.connection_state = ThermostatConnectionState.CONNECTING - await self._connecting_task + await self._thermostat.start_session( + host=self.connection_details_menu.host_set_line.text(), + port=self.connection_details_menu.port_set_spin.value(), + ) self._connecting_task = None self._thermostat.connection_state = ThermostatConnectionState.CONNECTED self._thermostat.start_watching()