forked from M-Labs/thermostat
Privatise ClientWatcher member variables
This commit is contained in:
parent
f189b86e06
commit
d7863e5dbd
|
@ -112,10 +112,10 @@ class ClientWatcher(QObject):
|
|||
postfilter_update = pyqtSignal(list)
|
||||
|
||||
def __init__(self, parent, client, update_s):
|
||||
self.update_s = update_s
|
||||
self.client = client
|
||||
self.watch_task = None
|
||||
self.poll_for_report = True
|
||||
self._update_s = update_s
|
||||
self._client = client
|
||||
self._watch_task = None
|
||||
self._poll_for_report = True
|
||||
super().__init__(parent)
|
||||
|
||||
async def run(self):
|
||||
|
@ -123,35 +123,35 @@ class ClientWatcher(QObject):
|
|||
while True:
|
||||
time = loop.time()
|
||||
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):
|
||||
self.fan_update.emit(await self.client.get_fan())
|
||||
self.pwm_update.emit(await self.client.get_pwm())
|
||||
if self.poll_for_report:
|
||||
self.report_update.emit(await self.client.report())
|
||||
self.pid_update.emit(await self.client.get_pid())
|
||||
self.thermistor_update.emit(await self.client.get_steinhart_hart())
|
||||
self.postfilter_update.emit(await self.client.get_postfilter())
|
||||
self.fan_update.emit(await self._client.get_fan())
|
||||
self.pwm_update.emit(await self._client.get_pwm())
|
||||
if self._poll_for_report:
|
||||
self.report_update.emit(await self._client.report())
|
||||
self.pid_update.emit(await self._client.get_pid())
|
||||
self.thermistor_update.emit(await self._client.get_steinhart_hart())
|
||||
self.postfilter_update.emit(await self._client.get_postfilter())
|
||||
|
||||
def start_watching(self):
|
||||
self.watch_task = asyncio.create_task(self.run())
|
||||
self._watch_task = asyncio.create_task(self.run())
|
||||
|
||||
def is_watching(self):
|
||||
return self.watch_task is not None
|
||||
return self._watch_task is not None
|
||||
|
||||
@pyqtSlot()
|
||||
def stop_watching(self):
|
||||
if self.watch_task is not None:
|
||||
self.watch_task.cancel()
|
||||
self.watch_task = None
|
||||
if self._watch_task is not None:
|
||||
self._watch_task.cancel()
|
||||
self._watch_task = None
|
||||
|
||||
def set_report_polling(self, enabled: bool):
|
||||
self.poll_for_report = enabled
|
||||
self._poll_for_report = enabled
|
||||
|
||||
@pyqtSlot(float)
|
||||
def set_update_s(self, update_s):
|
||||
self.update_s = update_s
|
||||
self._update_s = update_s
|
||||
|
||||
|
||||
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
|
|
Loading…
Reference in New Issue