From bfec9efbeceb6b29559af150deecede182f786f7 Mon Sep 17 00:00:00 2001 From: atse Date: Tue, 1 Aug 2023 10:33:53 +0800 Subject: [PATCH] Implement DFU mode --- pytec/pytec/aioclient.py | 13 +++++++++++++ pytec/tec_qt.py | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/pytec/pytec/aioclient.py b/pytec/pytec/aioclient.py index cf016ce..b17dea7 100644 --- a/pytec/pytec/aioclient.py +++ b/pytec/pytec/aioclient.py @@ -240,3 +240,16 @@ class Client: await self._writer.drain() await self.disconnect() + + async def dfu(self): + """Put the Thermostat in DFU update mode + + The client is disconnected as the Thermostat stops responding to + TCP commands in DFU update mode. The only way to exit it is by + power-cycling. + """ + async with self._command_lock: + self._writer.write("dfu\n".encode('utf-8')) + await self._writer.drain() + + await self.disconnect() diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 5dc718e..417740d 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -320,7 +320,16 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): self.actionReset.triggered.connect(reset_thermostat) self.thermostat_menu.addAction(self.actionReset) + @asyncSlot(bool) + async def dfu_mode(_): + await self._on_connection_changed(False) + await self.client.dfu() + + # TODO: add a firmware flashing GUI? + + self.actionEnter_DFU_Mode.triggered.connect(dfu_mode) self.thermostat_menu.addAction(self.actionEnter_DFU_Mode) + self.thermostat_menu.addAction(self.actionNetwork_Settings) self.thermostat_menu.addAction(self.actionLoad_all_configs) self.thermostat_menu.addAction(self.actionSave_all_configs)