From abe08e4be64ac9f8269c54c5706fe16f6b3d5349 Mon Sep 17 00:00:00 2001 From: atse Date: Mon, 8 Jul 2024 11:18:02 +0800 Subject: [PATCH] Use asserts to check for connectivity --- pytec/tec_qt.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index af9f928..9376a01 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -356,8 +356,8 @@ class MainWindow(QtWidgets.QMainWindow): @asyncSlot(int) async def fan_set_request(self, value): - if not self.client.connected(): - return + assert self.client.connected() + 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) @@ -367,8 +367,8 @@ class MainWindow(QtWidgets.QMainWindow): @asyncSlot(int) async def fan_auto_set_request(self, enabled): - if not self.client.connected(): - return + assert self.client.connected() + if enabled: await self.client.set_fan("auto") self.fan_update(await self.client.get_fan()) @@ -379,19 +379,27 @@ class MainWindow(QtWidgets.QMainWindow): @asyncSlot(int) async def save_cfg_request(self, ch): + assert self.thermostat.connected() + await self.thermostat.save_cfg(str(ch)) @asyncSlot(int) async def load_cfg_request(self, ch): + assert self.thermostat.connected() + await self.thermostat.load_cfg(str(ch)) @asyncSlot(bool) async def dfu_request(self, _): + assert self.thermostat.connected() + await self._on_connection_changed(False) await self.thermostat.dfu() @asyncSlot(bool) async def reset_request(self, _): + assert self.thermostat.connected() + await self._on_connection_changed(False) await self.thermostat.reset() await asyncio.sleep(0.1) # Wait for the reset to start @@ -400,12 +408,16 @@ class MainWindow(QtWidgets.QMainWindow): @asyncSlot(bool) async def net_settings_request(self, _): + assert self.thermostat.connected() + ipv4 = await self.thermostat.get_ipv4() self.net_settings_input_diag = NetSettingsInputDiag(ipv4["addr"]) self.net_settings_input_diag.set_ipv4_act.connect(self.set_net_settings_request) @asyncSlot(str) async def set_net_settings_request(self, ipv4_settings): + assert self.thermostat.connected() + await self.thermostat.set_ipv4(ipv4_settings) await self.thermostat._client.end_session() await self._on_connection_changed(False)