From 581ce615783cc3ec3008ef8e4593ac965289dfe8 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 330995a..95904d0 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -376,8 +376,8 @@ class MainWindow(QtWidgets.QMainWindow): @asyncSlot(int) async def fan_set_request(self, value): - if not self.thermostat.connected(): - return + assert self.thermostat.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) @@ -387,8 +387,8 @@ class MainWindow(QtWidgets.QMainWindow): @asyncSlot(int) async def fan_auto_set_request(self, enabled): - if not self.thermostat.connected(): - return + assert self.thermostat.connected() + if enabled: await self.thermostat.set_fan("auto") self.fan_update(await self.thermostat.get_fan()) @@ -399,19 +399,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 @@ -420,12 +428,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)