forked from M-Labs/thermostat
Invert logic, connect first
This commit is contained in:
parent
c6ca2b3490
commit
0252c7b0e4
|
@ -145,11 +145,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||
|
||||
ip, port = self.ip_set_line.text(), self.port_set_spin.value()
|
||||
try:
|
||||
if tec_client:
|
||||
await tec_client.disconnect()
|
||||
tec_client = None
|
||||
self._on_connection_changed(False)
|
||||
else:
|
||||
if tec_client is None:
|
||||
self.status_lbl.setText("Connecting...")
|
||||
tec_client = Client()
|
||||
await tec_client.connect(host=ip, port=port, timeout=30)
|
||||
|
@ -164,6 +160,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||
)
|
||||
QtWidgets.QApplication.instance().aboutToQuit.connect(client_watcher.stop_watching)
|
||||
self.client_watcher_task = asyncio.create_task(client_watcher.run())
|
||||
else:
|
||||
await tec_client.disconnect()
|
||||
tec_client = None
|
||||
self._on_connection_changed(False)
|
||||
except Exception as e:
|
||||
logging.error(f"Failed communicating to the {ip}:{port}: {e}")
|
||||
self._on_connection_changed(False)
|
||||
|
|
Loading…
Reference in New Issue