From b83cef24c75e5a238c725de686aa9cef01419ad8 Mon Sep 17 00:00:00 2001 From: atse Date: Mon, 8 Jul 2024 11:15:42 +0800 Subject: [PATCH] Use thermostat data model --- pytec/pytec/gui/model/thermostat.py | 13 +++++++++++-- pytec/tec_qt.py | 18 +++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/pytec/pytec/gui/model/thermostat.py b/pytec/pytec/gui/model/thermostat.py index 90ad78b..e68f044 100644 --- a/pytec/pytec/gui/model/thermostat.py +++ b/pytec/pytec/gui/model/thermostat.py @@ -25,6 +25,9 @@ class Thermostat(QObject, metaclass=PropertyMeta): self._poll_for_report = True super().__init__(parent) + async def start_session(self, host, port): + await self._client.start_session(host, port, timeout=5) + async def run(self): self.task = asyncio.create_task(self.update_params()) while True: @@ -60,10 +63,10 @@ class Thermostat(QObject, metaclass=PropertyMeta): self.postfilter = await self._client.get_postfilter() def connected(self): - return self._client.connected + return self._client.connected() def connecting(self): - return self._client.connecting + return self._client.connecting() def start_watching(self): self._watch_task = asyncio.create_task(self.run()) @@ -123,3 +126,9 @@ class Thermostat(QObject, metaclass=PropertyMeta): @pyqtSlot(float) def set_update_s(self, update_s): self._update_s = update_s + + async def set_fan(self, power="auto"): + self._client.set_fan(power) + + async def get_fan(self): + return await self._client.get_fan() diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 12b6c62..330995a 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -249,14 +249,14 @@ class MainWindow(QtWidgets.QMainWindow): self.conn_menu.port_set_spin.value(), ) try: - if not (self.client.connecting() or self.client.connected()): + if not (self.thermostat.connecting() or self.thermostat.connected()): self.status_lbl.setText("Connecting...") self.connect_btn.setText("Stop") self.conn_menu.host_set_line.setEnabled(False) self.conn_menu.port_set_spin.setEnabled(False) try: - await self.client.start_session(host=host, port=port, timeout=5) + await self.thermostat.start_session(host=host, port=port) except StoppedConnecting: return await self._on_connection_changed(True) @@ -273,7 +273,7 @@ class MainWindow(QtWidgets.QMainWindow): @asyncSlot() async def bail(self): await self._on_connection_changed(False) - await self.client.end_session() + await self.thermostat.disconnect() @asyncSlot(object, object) async def send_command(self, param, changes): @@ -376,24 +376,24 @@ class MainWindow(QtWidgets.QMainWindow): @asyncSlot(int) async def fan_set_request(self, value): - if not self.client.connected(): + if not self.thermostat.connected(): return if self.thermostat_ctrl_menu.fan_auto_box.isChecked(): with QSignalBlocker(self.thermostat_ctrl_menu.fan_auto_box): self.thermostat_ctrl_menu.fan_auto_box.setChecked(False) - await self.client.set_fan(value) + await self.thermostat.set_fan(value) if not self.hw_rev_data["settings"]["fan_pwm_recommended"]: self.thermostat_ctrl_menu.set_fan_pwm_warning() @asyncSlot(int) async def fan_auto_set_request(self, enabled): - if not self.client.connected(): + if not self.thermostat.connected(): return if enabled: - await self.client.set_fan("auto") - self.fan_update(await self.client.get_fan()) + await self.thermostat.set_fan("auto") + self.fan_update(await self.thermostat.get_fan()) else: - await self.client.set_fan( + await self.thermostat.set_fan( self.thermostat_ctrl_menu.fan_power_slider.value() )