diff --git a/pytec/pytec/gui/model/thermostat.py b/pytec/pytec/gui/model/thermostat.py index ce6b69a..a87f401 100644 --- a/pytec/pytec/gui/model/thermostat.py +++ b/pytec/pytec/gui/model/thermostat.py @@ -41,6 +41,28 @@ class Thermostat(QObject, metaclass=PropertyMeta): await self._client.connect(host, port) self.hw_rev = await self._client.hw_rev() + @asyncSlot() + async def end_session(self): + self.stop_watching() + + if self.disconnect_cb is not None: + if asyncio.iscoroutinefunction(self.disconnect_cb): + await self.disconnect_cb() + else: + self.disconnect_cb() + + await self._client.disconnect() + + def start_watching(self): + self._watch_task = asyncio.create_task(self.run()) + + def stop_watching(self): + if self._watch_task is not None: + self._watch_task.cancel() + self._watch_task = None + self._update_params_task.cancel() + self._update_params_task = None + async def run(self): self._update_params_task = asyncio.create_task(self.update_params()) while True: @@ -74,27 +96,9 @@ class Thermostat(QObject, metaclass=PropertyMeta): def connected(self): return self._client.connected() - def start_watching(self): - self._watch_task = asyncio.create_task(self.run()) - - def stop_watching(self): - if self._watch_task is not None: - self._watch_task.cancel() - self._watch_task = None - self._update_params_task.cancel() - self._update_params_task = None - - @asyncSlot() - async def end_session(self): - self.stop_watching() - - if self.disconnect_cb is not None: - if asyncio.iscoroutinefunction(self.disconnect_cb): - await self.disconnect_cb() - else: - self.disconnect_cb() - - await self._client.disconnect() + @pyqtSlot(float) + def set_update_s(self, update_s): + self._update_s = update_s async def set_ipv4(self, ipv4): await self._client.set_param("ipv4", ipv4) @@ -116,10 +120,6 @@ class Thermostat(QObject, metaclass=PropertyMeta): async def reset(self): await self._client.reset() - @pyqtSlot(float) - def set_update_s(self, update_s): - self._update_s = update_s - async def set_fan(self, power="auto"): await self._client.set_fan(power)