No need to create a new task for waiting

This commit is contained in:
atse 2024-09-09 18:29:24 +08:00
parent 3b2743c079
commit 2b02ea334a

View File

@ -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(
self._connecting_task = asyncio.current_task()
self._thermostat.connection_state = ThermostatConnectionState.CONNECTING
await self._thermostat.start_session(
host=self.connection_details_menu.host_set_line.text(),
port=self.connection_details_menu.port_set_spin.value(),
)
)
self._thermostat.connection_state = ThermostatConnectionState.CONNECTING
await self._connecting_task
self._connecting_task = None
self._thermostat.connection_state = ThermostatConnectionState.CONNECTED
self._thermostat.start_watching()