Privatise ClientWatcher member variables

This commit is contained in:
atse 2023-08-16 12:25:51 +08:00
parent f189b86e06
commit d7863e5dbd
1 changed files with 19 additions and 19 deletions

View File

@ -112,10 +112,10 @@ class ClientWatcher(QObject):
postfilter_update = pyqtSignal(list) postfilter_update = pyqtSignal(list)
def __init__(self, parent, client, update_s): def __init__(self, parent, client, update_s):
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.poll_for_report = True self._poll_for_report = True
super().__init__(parent) super().__init__(parent)
async def run(self): async def run(self):
@ -123,35 +123,35 @@ class ClientWatcher(QObject):
while True: while True:
time = loop.time() time = loop.time()
await self.update_params() await self.update_params()
await asyncio.sleep(self.update_s - (loop.time() - time)) await asyncio.sleep(self._update_s - (loop.time() - time))
async def update_params(self): async def update_params(self):
self.fan_update.emit(await self.client.get_fan()) self.fan_update.emit(await self._client.get_fan())
self.pwm_update.emit(await self.client.get_pwm()) self.pwm_update.emit(await self._client.get_pwm())
if self.poll_for_report: if self._poll_for_report:
self.report_update.emit(await self.client.report()) self.report_update.emit(await self._client.report())
self.pid_update.emit(await self.client.get_pid()) self.pid_update.emit(await self._client.get_pid())
self.thermistor_update.emit(await self.client.get_steinhart_hart()) self.thermistor_update.emit(await self._client.get_steinhart_hart())
self.postfilter_update.emit(await self.client.get_postfilter()) self.postfilter_update.emit(await self._client.get_postfilter())
def start_watching(self): def start_watching(self):
self.watch_task = asyncio.create_task(self.run()) self._watch_task = asyncio.create_task(self.run())
def is_watching(self): def is_watching(self):
return self.watch_task is not None return self._watch_task is not None
@pyqtSlot() @pyqtSlot()
def stop_watching(self): def stop_watching(self):
if self.watch_task is not None: if self._watch_task is not None:
self.watch_task.cancel() self._watch_task.cancel()
self.watch_task = None self._watch_task = None
def set_report_polling(self, enabled: bool): def set_report_polling(self, enabled: bool):
self.poll_for_report = enabled self._poll_for_report = enabled
@pyqtSlot(float) @pyqtSlot(float)
def set_update_s(self, update_s): def set_update_s(self, update_s):
self.update_s = update_s self._update_s = update_s
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):