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.
This commit is contained in:
atse 2024-06-20 15:25:04 +08:00
parent c978a0dda6
commit 872b7e02f3
2 changed files with 8 additions and 2 deletions

View File

@ -13,7 +13,6 @@ class WrappedClient(QObject, Client):
try: try:
return await super()._read_line() return await super()._read_line()
except (Exception, TimeoutError, asyncio.exceptions.TimeoutError): except (Exception, TimeoutError, asyncio.exceptions.TimeoutError):
logging.error("Client connection error, disconnecting", exc_info=True)
self.connection_error.emit() self.connection_error.emit()

View File

@ -69,7 +69,14 @@ class MainWindow(QtWidgets.QMainWindow):
self.info_box = InfoBox() self.info_box = InfoBox()
self.client = WrappedClient(self) 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.thermostat = Thermostat(
self, self.client, self.report_refresh_spin.value() self, self.client, self.report_refresh_spin.value()