forked from M-Labs/thermostat
Remove report mode from thermostat data model
This commit is contained in:
parent
7cf5bcb400
commit
a84ebdd6ad
@ -31,8 +31,6 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
self._update_s = update_s
|
self._update_s = update_s
|
||||||
self._client = AsyncioClient()
|
self._client = AsyncioClient()
|
||||||
self._watch_task = None
|
self._watch_task = None
|
||||||
self._report_mode_task = None
|
|
||||||
self._poll_for_report = True
|
|
||||||
self._update_params_task = None
|
self._update_params_task = None
|
||||||
self.disconnect_cb = disconnect_cb
|
self.disconnect_cb = disconnect_cb
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@ -62,27 +60,11 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
await asyncio.sleep(self._update_s)
|
await asyncio.sleep(self._update_s)
|
||||||
|
|
||||||
async def update_params(self):
|
async def update_params(self):
|
||||||
if self._poll_for_report:
|
self.fan, self.pwm, self.report, 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(),
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.fan, self.pwm, self.pid, self.thermistor, self.postfilter = (
|
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
self._client.get_fan(),
|
self._client.get_fan(),
|
||||||
self._client.get_pwm(),
|
self._client.get_pwm(),
|
||||||
|
self._client.report(),
|
||||||
self._client.get_pid(),
|
self._client.get_pid(),
|
||||||
self._client.get_steinhart_hart(),
|
self._client.get_steinhart_hart(),
|
||||||
self._client.get_postfilter(),
|
self._client.get_postfilter(),
|
||||||
@ -98,26 +80,13 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
@asyncSlot()
|
@asyncSlot()
|
||||||
async def stop_watching(self):
|
async def stop_watching(self):
|
||||||
if self._watch_task is not None:
|
if self._watch_task is not None:
|
||||||
await self.set_report_mode(False)
|
|
||||||
self._watch_task.cancel()
|
self._watch_task.cancel()
|
||||||
self._watch_task = None
|
self._watch_task = None
|
||||||
self._update_params_task.cancel()
|
self._update_params_task.cancel()
|
||||||
self._update_params_task = None
|
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()
|
@asyncSlot()
|
||||||
async def end_session(self):
|
async def end_session(self):
|
||||||
await self.set_report_mode(False)
|
|
||||||
self.stop_watching()
|
self.stop_watching()
|
||||||
|
|
||||||
if self.disconnect_cb is not None:
|
if self.disconnect_cb is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user