From 872b7e02f3d22d75dd4d9e0d26c82fa065cb7547 Mon Sep 17 00:00:00 2001 From: atse Date: Thu, 20 Jun 2024 15:25:04 +0800 Subject: [PATCH] Make interrupted connection handling more elegant * Show a disconnected info box informing the user that the device was forcefully disconnected and requires user intervention. * Don't print exception info to console on connection failure to avoid cluttering it up with programmer info. --- pytec/model/thermostat.py | 1 - pytec/tec_qt.py | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pytec/model/thermostat.py b/pytec/model/thermostat.py index d1a47aa..08e7429 100644 --- a/pytec/model/thermostat.py +++ b/pytec/model/thermostat.py @@ -13,7 +13,6 @@ class WrappedClient(QObject, Client): try: return await super()._read_line() except (Exception, TimeoutError, asyncio.exceptions.TimeoutError): - logging.error("Client connection error, disconnecting", exc_info=True) self.connection_error.emit() diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 126674b..41318fe 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -69,7 +69,14 @@ class MainWindow(QtWidgets.QMainWindow): self.info_box = InfoBox() self.client = WrappedClient(self) - self.client.connection_error.connect(self.bail) + + def handle_connection_error(): + logging.error("Client connection error, disconnecting") + self.info_box.display_info_box("Connection Error", "Thermostat disconnected. Is it unplugged?") + + self.bail() + + self.client.connection_error.connect(handle_connection_error) self.thermostat = Thermostat( self, self.client, self.report_refresh_spin.value()