Remove report mode from thermostat data model

This commit is contained in:
atse 2024-09-09 12:45:16 +08:00
parent 7cf5bcb400
commit a84ebdd6ad

View File

@ -31,8 +31,6 @@ class Thermostat(QObject, metaclass=PropertyMeta):
self._update_s = update_s
self._client = AsyncioClient()
self._watch_task = None
self._report_mode_task = None
self._poll_for_report = True
self._update_params_task = None
self.disconnect_cb = disconnect_cb
super().__init__(parent)
@ -62,15 +60,8 @@ class Thermostat(QObject, metaclass=PropertyMeta):
await asyncio.sleep(self._update_s)
async def update_params(self):
if self._poll_for_report:
(
self.fan,
self.pwm,
self.report,
self.pid,
self.thermistor,
self.postfilter,
) = await asyncio.gather(
self.fan, self.pwm, self.report, self.pid, self.thermistor, self.postfilter = (
await asyncio.gather(
self._client.get_fan(),
self._client.get_pwm(),
self._client.report(),
@ -78,16 +69,7 @@ class Thermostat(QObject, metaclass=PropertyMeta):
self._client.get_steinhart_hart(),
self._client.get_postfilter(),
)
else:
self.fan, self.pwm, self.pid, self.thermistor, self.postfilter = (
await asyncio.gather(
self._client.get_fan(),
self._client.get_pwm(),
self._client.get_pid(),
self._client.get_steinhart_hart(),
self._client.get_postfilter(),
)
)
)
def connected(self):
return self._client.connected()
@ -98,26 +80,13 @@ class Thermostat(QObject, metaclass=PropertyMeta):
@asyncSlot()
async def stop_watching(self):
if self._watch_task is not None:
await self.set_report_mode(False)
self._watch_task.cancel()
self._watch_task = None
self._update_params_task.cancel()
self._update_params_task = None
async def set_report_mode(self, enabled: bool):
self._poll_for_report = not enabled
if enabled:
self._report_mode_task = asyncio.create_task(self.report_mode())
else:
self._client.stop_report_mode()
async def report_mode(self):
async for report in self._client.report_mode():
self.report_update.emit(report)
@asyncSlot()
async def end_session(self):
await self.set_report_mode(False)
self.stop_watching()
if self.disconnect_cb is not None: