1
0
forked from M-Labs/thermostat

task -> _connecting_task

This commit is contained in:
atse 2024-08-23 15:42:42 +08:00
parent 2b265d6e36
commit a087622371

View File

@ -34,23 +34,23 @@ class Thermostat(QObject, metaclass=PropertyMeta):
self._watch_task = None self._watch_task = None
self._report_mode_task = None self._report_mode_task = None
self._poll_for_report = True self._poll_for_report = True
self.task = None self._update_params_task = None
super().__init__(parent) super().__init__(parent)
async def run(self): async def run(self):
self.task = asyncio.create_task(self.update_params()) self._update_params_task = asyncio.create_task(self.update_params())
while True: while True:
if self.task.done(): if self._update_params_task.done():
if self.task.exception() is not None: if self.task.exception() is not None:
try: try:
raise self.task.exception() raise self._update_params_task.exception()
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.error( logging.error(
"Encountered an error while polling for information from Thermostat.", "Encountered an error while polling for information from Thermostat.",
exc_info=True, exc_info=True,
) )
_ = self.task.result() _ = self.task.result()
self.task = asyncio.create_task(self.update_params()) self._update_params_task = asyncio.create_task(self.update_params())
await asyncio.sleep(self._update_s) await asyncio.sleep(self._update_s)
async def get_hw_rev(self): async def get_hw_rev(self):
@ -84,8 +84,8 @@ class Thermostat(QObject, metaclass=PropertyMeta):
await self.set_report_mode(False) await self.set_report_mode(False)
self._watch_task.cancel() self._watch_task.cancel()
self._watch_task = None self._watch_task = None
self.task.cancel() self._update_params_task.cancel()
self.task = None self._update_params_task = None
async def set_report_mode(self, enabled: bool): async def set_report_mode(self, enabled: bool):
self._poll_for_report = not enabled self._poll_for_report = not enabled