forked from M-Labs/thermostat
parent
fd83ee23e1
commit
917a2546cc
|
@ -36,14 +36,13 @@ class ClientWatcher(QObject):
|
|||
|
||||
def __init__(self, parent, client, update_s):
|
||||
self.update_s = update_s
|
||||
self.running = False
|
||||
self.client = client
|
||||
self.watch_task = None
|
||||
super().__init__(parent)
|
||||
|
||||
async def run(self):
|
||||
loop = asyncio.get_running_loop()
|
||||
while self.running:
|
||||
while True:
|
||||
time = loop.time()
|
||||
await self.update_params()
|
||||
await asyncio.sleep(self.update_s - (loop.time() - time))
|
||||
|
@ -52,12 +51,10 @@ class ClientWatcher(QObject):
|
|||
self.fan_update.emit(await self.client.fan())
|
||||
|
||||
def start_watching(self):
|
||||
self.running = True
|
||||
self.watch_task = asyncio.create_task(self.run())
|
||||
|
||||
@pyqtSlot()
|
||||
def stop_watching(self):
|
||||
self.running = False
|
||||
self.watch_task.cancel()
|
||||
|
||||
@pyqtSlot(float)
|
||||
|
|
Loading…
Reference in New Issue