forked from M-Labs/thermostat
Move report mode bookkeeping into ClientWatcher
This commit is contained in:
parent
898a6891cf
commit
aeecde09af
|
@ -115,6 +115,7 @@ class ClientWatcher(QObject):
|
||||||
self._update_s = update_s
|
self._update_s = update_s
|
||||||
self._client = client
|
self._client = client
|
||||||
self._watch_task = None
|
self._watch_task = None
|
||||||
|
self._report_mode_task = None
|
||||||
self._poll_for_report = True
|
self._poll_for_report = True
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
|
@ -146,8 +147,20 @@ class ClientWatcher(QObject):
|
||||||
self._watch_task.cancel()
|
self._watch_task.cancel()
|
||||||
self._watch_task = None
|
self._watch_task = None
|
||||||
|
|
||||||
def set_report_polling(self, enabled: bool):
|
async def set_report_mode(self, enabled: bool):
|
||||||
self._poll_for_report = enabled
|
self._poll_for_report = not enabled
|
||||||
|
if enabled:
|
||||||
|
self._report_mode_task = asyncio.create_task(self.report_mode())
|
||||||
|
else:
|
||||||
|
self._client.stop_report_mode()
|
||||||
|
if self._report_mode_task is not None:
|
||||||
|
await self._report_mode_task
|
||||||
|
self._report_mode_task = None
|
||||||
|
|
||||||
|
async def report_mode(self):
|
||||||
|
async for report in self._client.report_mode():
|
||||||
|
self.report_update.emit(report)
|
||||||
|
|
||||||
|
|
||||||
@pyqtSlot(float)
|
@pyqtSlot(float)
|
||||||
def set_update_s(self, update_s):
|
def set_update_s(self, update_s):
|
||||||
|
@ -213,8 +226,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
lambda: self.client_watcher.set_update_s(self.report_refresh_spin.value())
|
lambda: self.client_watcher.set_update_s(self.report_refresh_spin.value())
|
||||||
)
|
)
|
||||||
|
|
||||||
self.report_mode_task = None
|
|
||||||
|
|
||||||
if args.connect:
|
if args.connect:
|
||||||
if args.IP:
|
if args.IP:
|
||||||
self.host_set_line.setText(args.IP)
|
self.host_set_line.setText(args.IP)
|
||||||
|
@ -516,7 +527,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
self.fan_pwm_warning.setToolTip("")
|
self.fan_pwm_warning.setToolTip("")
|
||||||
self.clear_graphs()
|
self.clear_graphs()
|
||||||
self.report_box.setChecked(False)
|
self.report_box.setChecked(False)
|
||||||
await self.stop_report_mode()
|
await self.client_watcher.set_report_mode(False)
|
||||||
self.client_watcher.stop_watching()
|
self.client_watcher.stop_watching()
|
||||||
self.status_lbl.setText("Disconnected")
|
self.status_lbl.setText("Disconnected")
|
||||||
|
|
||||||
|
@ -570,22 +581,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
|
|
||||||
@asyncSlot(int)
|
@asyncSlot(int)
|
||||||
async def on_report_box_stateChanged(self, enabled):
|
async def on_report_box_stateChanged(self, enabled):
|
||||||
self.client_watcher.set_report_polling(not enabled)
|
await self.client_watcher.set_report_mode(enabled)
|
||||||
if enabled:
|
|
||||||
self.report_mode_task = asyncio.create_task(self.report_mode())
|
|
||||||
else:
|
|
||||||
self.client.stop_report_mode()
|
|
||||||
|
|
||||||
async def report_mode(self):
|
|
||||||
async for report in self.client.report_mode():
|
|
||||||
self.plot(report)
|
|
||||||
self.update_report(report)
|
|
||||||
|
|
||||||
async def stop_report_mode(self):
|
|
||||||
if self.report_mode_task is not None:
|
|
||||||
self.client.stop_report_mode()
|
|
||||||
await self.report_mode_task
|
|
||||||
self.report_mode_task = None
|
|
||||||
|
|
||||||
@asyncClose
|
@asyncClose
|
||||||
async def closeEvent(self, event):
|
async def closeEvent(self, event):
|
||||||
|
|
Loading…
Reference in New Issue