forked from M-Labs/thermostat
parent
fa60439e39
commit
659d0d0835
|
@ -19,13 +19,22 @@ class Client:
|
||||||
|
|
||||||
await self._check_zero_limits()
|
await self._check_zero_limits()
|
||||||
|
|
||||||
|
def is_connecting(self):
|
||||||
|
return self._connecting_task is not None
|
||||||
|
|
||||||
|
def is_connected(self):
|
||||||
|
return self._reader is not None
|
||||||
|
|
||||||
async def disconnect(self):
|
async def disconnect(self):
|
||||||
if self._connecting_task is not None:
|
if self._connecting_task is not None:
|
||||||
self._connecting_task.cancel()
|
self._connecting_task.cancel()
|
||||||
|
self._connecting_task = None
|
||||||
return
|
return
|
||||||
|
|
||||||
self._writer.close()
|
self._writer.close()
|
||||||
await self._writer.wait_closed()
|
await self._writer.wait_closed()
|
||||||
|
self._reader = None
|
||||||
|
self._writer = None
|
||||||
|
|
||||||
async def _check_zero_limits(self):
|
async def _check_zero_limits(self):
|
||||||
pwm_report = await self.get_pwm()
|
pwm_report = await self.get_pwm()
|
||||||
|
|
|
@ -74,7 +74,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
|
|
||||||
self.fan_pwm_recommended = False
|
self.fan_pwm_recommended = False
|
||||||
|
|
||||||
self.tec_client: Client = None
|
self.tec_client = Client()
|
||||||
self.client_watcher: ClientWatcher = None
|
self.client_watcher: ClientWatcher = None
|
||||||
|
|
||||||
if args.connect:
|
if args.connect:
|
||||||
|
@ -128,7 +128,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
|
|
||||||
@asyncSlot(int)
|
@asyncSlot(int)
|
||||||
async def fan_set(self, value):
|
async def fan_set(self, value):
|
||||||
if self.tec_client is None or self.fan_auto_box.isChecked():
|
if not self.tec_client.is_connected() or self.fan_auto_box.isChecked():
|
||||||
return
|
return
|
||||||
await self.tec_client.set_param("fan", value)
|
await self.tec_client.set_param("fan", value)
|
||||||
if not self.fan_pwm_recommended:
|
if not self.fan_pwm_recommended:
|
||||||
|
@ -136,7 +136,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
|
|
||||||
@asyncSlot(int)
|
@asyncSlot(int)
|
||||||
async def fan_auto_set(self, enabled):
|
async def fan_auto_set(self, enabled):
|
||||||
if self.tec_client is None:
|
if not self.tec_client.is_connected():
|
||||||
return
|
return
|
||||||
self.fan_power_slider.setEnabled(not enabled)
|
self.fan_power_slider.setEnabled(not enabled)
|
||||||
if enabled:
|
if enabled:
|
||||||
|
@ -149,20 +149,19 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
async def closeEvent(self, event):
|
async def closeEvent(self, event):
|
||||||
if self.client_watcher is not None:
|
if self.client_watcher is not None:
|
||||||
self.client_watcher.stop_watching()
|
self.client_watcher.stop_watching()
|
||||||
if self.tec_client is not None:
|
if self.tec_client.is_connecting() or self.tec_client.is_connected():
|
||||||
await self.tec_client.disconnect()
|
await self.tec_client.disconnect()
|
||||||
|
|
||||||
@asyncSlot()
|
@asyncSlot()
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
ip, port = self.ip_set_line.text(), self.port_set_spin.value()
|
ip, port = self.ip_set_line.text(), self.port_set_spin.value()
|
||||||
try:
|
try:
|
||||||
if self.tec_client is None:
|
if not (self.tec_client.is_connecting() or self.tec_client.is_connected()):
|
||||||
self.status_lbl.setText("Connecting...")
|
self.status_lbl.setText("Connecting...")
|
||||||
self.ip_set_line.setEnabled(False)
|
self.ip_set_line.setEnabled(False)
|
||||||
self.port_set_spin.setEnabled(False)
|
self.port_set_spin.setEnabled(False)
|
||||||
self.connect_btn.setText("Stop")
|
self.connect_btn.setText("Stop")
|
||||||
|
|
||||||
self.tec_client = Client()
|
|
||||||
try:
|
try:
|
||||||
await self.tec_client.connect(host=ip, port=port, timeout=30)
|
await self.tec_client.connect(host=ip, port=port, timeout=30)
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
|
@ -184,7 +183,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
self.client_watcher = None
|
self.client_watcher = None
|
||||||
|
|
||||||
await self.tec_client.disconnect()
|
await self.tec_client.disconnect()
|
||||||
self.tec_client = None
|
|
||||||
self._on_connection_changed(False)
|
self._on_connection_changed(False)
|
||||||
|
|
||||||
except (OSError, TimeoutError) as e:
|
except (OSError, TimeoutError) as e:
|
||||||
|
|
Loading…
Reference in New Issue