Add proper set_fan and get_fan coroutine methods

This commit is contained in:
atse 2023-08-11 16:08:50 +08:00
parent f6dc882d9b
commit a54773d3ae
2 changed files with 14 additions and 10 deletions

View File

@ -160,6 +160,10 @@ class Client:
""" """
return await self._get_conf("postfilter") return await self._get_conf("postfilter")
async def get_fan(self):
"""Get Thermostat current fan settings"""
return await self._command("fan")
async def report(self): async def report(self):
"""Obtain one-time report on measurement values""" """Obtain one-time report on measurement values"""
return await self._command("report") return await self._command("report")
@ -219,6 +223,10 @@ class Client:
value = str(value) value = str(value)
await self._command(topic, str(channel), field, value) await self._command(topic, str(channel), field, value)
async def set_fan(self, power="auto"):
"""Set fan power"""
await self._command("fan", str(power))
async def power_up(self, channel, target): async def power_up(self, channel, target):
"""Start closed-loop mode""" """Start closed-loop mode"""
await self.set_param("pid", channel, "target", value=target) await self.set_param("pid", channel, "target", value=target)
@ -236,10 +244,6 @@ class Client:
"""Get Thermostat hardware revision""" """Get Thermostat hardware revision"""
return await self._command("hwrev") return await self._command("hwrev")
async def fan(self):
"""Get Thermostat current fan settings"""
return await self._command("fan")
async def reset(self): async def reset(self):
"""Reset the Thermostat """Reset the Thermostat

View File

@ -111,7 +111,7 @@ class ClientWatcher(QObject):
await asyncio.sleep(self.update_s - (loop.time() - time)) await asyncio.sleep(self.update_s - (loop.time() - time))
async def update_params(self): async def update_params(self):
self.fan_update.emit(await self.client.fan()) self.fan_update.emit(await self.client.get_fan())
self.pwm_update.emit(await self.client.get_pwm()) self.pwm_update.emit(await self.client.get_pwm())
if self.poll_for_report: if self.poll_for_report:
self.report_update.emit(await self.client.report()) self.report_update.emit(await self.client.report())
@ -486,7 +486,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.hw_rev_data = await self.client.hw_rev() self.hw_rev_data = await self.client.hw_rev()
self._status(self.hw_rev_data) self._status(self.hw_rev_data)
self.client_watcher.start_watching() self.client_watcher.start_watching()
self.fan_update(await self.client.fan()) self.fan_update(await self.client.get_fan())
# await self.client.set_param("fan", 1) # await self.client.set_param("fan", 1)
else: else:
self.status_lbl.setText("Disconnected") self.status_lbl.setText("Disconnected")
@ -532,7 +532,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
if self.fan_auto_box.isChecked(): if self.fan_auto_box.isChecked():
with QSignalBlocker(self.fan_auto_box): with QSignalBlocker(self.fan_auto_box):
self.fan_auto_box.setChecked(False) self.fan_auto_box.setChecked(False)
await self.client.set_param("fan", value) await self.client.set_fan(value)
if not self.hw_rev_data["settings"]["fan_pwm_recommended"]: if not self.hw_rev_data["settings"]["fan_pwm_recommended"]:
self._set_fan_pwm_warning() self._set_fan_pwm_warning()
@ -541,10 +541,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
if not self.client.connected(): if not self.client.connected():
return return
if enabled: if enabled:
await self.client.set_param("fan", "auto") await self.client.set_fan("auto")
self.fan_update(await self.client.fan()) self.fan_update(await self.client.get_fan())
else: else:
await self.client.set_param("fan", self.fan_power_slider.value()) await self.client.set_fan(self.fan_power_slider.value())
@asyncSlot(int) @asyncSlot(int)
async def on_report_box_stateChanged(self, enabled): async def on_report_box_stateChanged(self, enabled):