forked from M-Labs/thermostat
Gather client_watcher managment into connect
This commit is contained in:
parent
0252c7b0e4
commit
9cf33abe06
|
@ -82,7 +82,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
self.connect_btn.click()
|
self.connect_btn.click()
|
||||||
|
|
||||||
def _on_connection_changed(self, result):
|
def _on_connection_changed(self, result):
|
||||||
global client_watcher
|
|
||||||
self.graph_group.setEnabled(result)
|
self.graph_group.setEnabled(result)
|
||||||
self.hw_rev_lbl.setEnabled(result)
|
self.hw_rev_lbl.setEnabled(result)
|
||||||
self.fan_group.setEnabled(result)
|
self.fan_group.setEnabled(result)
|
||||||
|
@ -95,10 +94,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
if not result:
|
if not result:
|
||||||
self.hw_rev_lbl.setText("Thermostat vX.Y")
|
self.hw_rev_lbl.setText("Thermostat vX.Y")
|
||||||
self.fan_group.setStyleSheet("")
|
self.fan_group.setStyleSheet("")
|
||||||
if client_watcher:
|
|
||||||
client_watcher.stop_watching()
|
|
||||||
client_watcher = None
|
|
||||||
self.client_watcher_task = None
|
|
||||||
|
|
||||||
def _hw_rev(self, hw_rev_d: dict):
|
def _hw_rev(self, hw_rev_d: dict):
|
||||||
logging.debug(hw_rev_d)
|
logging.debug(hw_rev_d)
|
||||||
|
@ -152,7 +147,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
self._on_connection_changed(True)
|
self._on_connection_changed(True)
|
||||||
self._hw_rev(await tec_client.hw_rev())
|
self._hw_rev(await tec_client.hw_rev())
|
||||||
# self.fan_update(await tec_client.fan())
|
# self.fan_update(await tec_client.fan())
|
||||||
if client_watcher is None:
|
|
||||||
client_watcher = ClientWatcher(self.main_widget, self.report_refresh_spin.value())
|
client_watcher = ClientWatcher(self.main_widget, self.report_refresh_spin.value())
|
||||||
client_watcher.fan_update.connect(self.fan_update)
|
client_watcher.fan_update.connect(self.fan_update)
|
||||||
self.report_apply_btn.clicked.connect(
|
self.report_apply_btn.clicked.connect(
|
||||||
|
@ -164,6 +159,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
await tec_client.disconnect()
|
await tec_client.disconnect()
|
||||||
tec_client = None
|
tec_client = None
|
||||||
self._on_connection_changed(False)
|
self._on_connection_changed(False)
|
||||||
|
|
||||||
|
client_watcher.stop_watching()
|
||||||
|
client_watcher = None
|
||||||
|
await self.client_watcher_task
|
||||||
|
self.client_watcher_task = None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Failed communicating to the {ip}:{port}: {e}")
|
logging.error(f"Failed communicating to the {ip}:{port}: {e}")
|
||||||
self._on_connection_changed(False)
|
self._on_connection_changed(False)
|
||||||
|
|
Loading…
Reference in New Issue