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