forked from M-Labs/thermostat
Use thermostat data model
This commit is contained in:
parent
54bedc3a83
commit
b83cef24c7
@ -25,6 +25,9 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
self._poll_for_report = True
|
self._poll_for_report = True
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
|
async def start_session(self, host, port):
|
||||||
|
await self._client.start_session(host, port, timeout=5)
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
self.task = asyncio.create_task(self.update_params())
|
self.task = asyncio.create_task(self.update_params())
|
||||||
while True:
|
while True:
|
||||||
@ -60,10 +63,10 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
self.postfilter = await self._client.get_postfilter()
|
self.postfilter = await self._client.get_postfilter()
|
||||||
|
|
||||||
def connected(self):
|
def connected(self):
|
||||||
return self._client.connected
|
return self._client.connected()
|
||||||
|
|
||||||
def connecting(self):
|
def connecting(self):
|
||||||
return self._client.connecting
|
return self._client.connecting()
|
||||||
|
|
||||||
def start_watching(self):
|
def start_watching(self):
|
||||||
self._watch_task = asyncio.create_task(self.run())
|
self._watch_task = asyncio.create_task(self.run())
|
||||||
@ -123,3 +126,9 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
@pyqtSlot(float)
|
@pyqtSlot(float)
|
||||||
def set_update_s(self, update_s):
|
def set_update_s(self, update_s):
|
||||||
self._update_s = update_s
|
self._update_s = update_s
|
||||||
|
|
||||||
|
async def set_fan(self, power="auto"):
|
||||||
|
self._client.set_fan(power)
|
||||||
|
|
||||||
|
async def get_fan(self):
|
||||||
|
return await self._client.get_fan()
|
||||||
|
@ -249,14 +249,14 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.conn_menu.port_set_spin.value(),
|
self.conn_menu.port_set_spin.value(),
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
if not (self.client.connecting() or self.client.connected()):
|
if not (self.thermostat.connecting() or self.thermostat.connected()):
|
||||||
self.status_lbl.setText("Connecting...")
|
self.status_lbl.setText("Connecting...")
|
||||||
self.connect_btn.setText("Stop")
|
self.connect_btn.setText("Stop")
|
||||||
self.conn_menu.host_set_line.setEnabled(False)
|
self.conn_menu.host_set_line.setEnabled(False)
|
||||||
self.conn_menu.port_set_spin.setEnabled(False)
|
self.conn_menu.port_set_spin.setEnabled(False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.client.start_session(host=host, port=port, timeout=5)
|
await self.thermostat.start_session(host=host, port=port)
|
||||||
except StoppedConnecting:
|
except StoppedConnecting:
|
||||||
return
|
return
|
||||||
await self._on_connection_changed(True)
|
await self._on_connection_changed(True)
|
||||||
@ -273,7 +273,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
@asyncSlot()
|
@asyncSlot()
|
||||||
async def bail(self):
|
async def bail(self):
|
||||||
await self._on_connection_changed(False)
|
await self._on_connection_changed(False)
|
||||||
await self.client.end_session()
|
await self.thermostat.disconnect()
|
||||||
|
|
||||||
@asyncSlot(object, object)
|
@asyncSlot(object, object)
|
||||||
async def send_command(self, param, changes):
|
async def send_command(self, param, changes):
|
||||||
@ -376,24 +376,24 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
@asyncSlot(int)
|
@asyncSlot(int)
|
||||||
async def fan_set_request(self, value):
|
async def fan_set_request(self, value):
|
||||||
if not self.client.connected():
|
if not self.thermostat.connected():
|
||||||
return
|
return
|
||||||
if self.thermostat_ctrl_menu.fan_auto_box.isChecked():
|
if self.thermostat_ctrl_menu.fan_auto_box.isChecked():
|
||||||
with QSignalBlocker(self.thermostat_ctrl_menu.fan_auto_box):
|
with QSignalBlocker(self.thermostat_ctrl_menu.fan_auto_box):
|
||||||
self.thermostat_ctrl_menu.fan_auto_box.setChecked(False)
|
self.thermostat_ctrl_menu.fan_auto_box.setChecked(False)
|
||||||
await self.client.set_fan(value)
|
await self.thermostat.set_fan(value)
|
||||||
if not self.hw_rev_data["settings"]["fan_pwm_recommended"]:
|
if not self.hw_rev_data["settings"]["fan_pwm_recommended"]:
|
||||||
self.thermostat_ctrl_menu.set_fan_pwm_warning()
|
self.thermostat_ctrl_menu.set_fan_pwm_warning()
|
||||||
|
|
||||||
@asyncSlot(int)
|
@asyncSlot(int)
|
||||||
async def fan_auto_set_request(self, enabled):
|
async def fan_auto_set_request(self, enabled):
|
||||||
if not self.client.connected():
|
if not self.thermostat.connected():
|
||||||
return
|
return
|
||||||
if enabled:
|
if enabled:
|
||||||
await self.client.set_fan("auto")
|
await self.thermostat.set_fan("auto")
|
||||||
self.fan_update(await self.client.get_fan())
|
self.fan_update(await self.thermostat.get_fan())
|
||||||
else:
|
else:
|
||||||
await self.client.set_fan(
|
await self.thermostat.set_fan(
|
||||||
self.thermostat_ctrl_menu.fan_power_slider.value()
|
self.thermostat_ctrl_menu.fan_power_slider.value()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user