Remove report mode from thermostat data model

This commit is contained in:
atse 2024-09-09 12:45:16 +08:00
parent 1797322803
commit 5153ccdd77
1 changed files with 3 additions and 34 deletions

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,27 +60,11 @@ 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._client.get_fan(),
self._client.get_pwm(),
self._client.report(),
self._client.get_pid(),
self._client.get_steinhart_hart(),
self._client.get_postfilter(),
)
else:
self.fan, self.pwm, self.pid, self.thermistor, self.postfilter = (
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(),
self._client.get_pid(),
self._client.get_steinhart_hart(),
self._client.get_postfilter(),
@ -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: