forked from M-Labs/thermostat
Remove report mode from thermostat data model
This commit is contained in:
parent
1797322803
commit
5153ccdd77
|
@ -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,15 +60,8 @@ 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 = (
|
||||||
(
|
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_fan(),
|
||||||
self._client.get_pwm(),
|
self._client.get_pwm(),
|
||||||
self._client.report(),
|
self._client.report(),
|
||||||
|
@ -78,16 +69,7 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
||||||
self._client.get_steinhart_hart(),
|
self._client.get_steinhart_hart(),
|
||||||
self._client.get_postfilter(),
|
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):
|
def connected(self):
|
||||||
return self._client.connected()
|
return self._client.connected()
|
||||||
|
@ -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