forked from M-Labs/thermostat
Integrate WrappedClient into Thermostat model
This commit is contained in:
parent
37c982b786
commit
c1fdcda621
@ -1,4 +1,3 @@
|
||||
from pytec.aioclient import Client
|
||||
from PyQt6.QtCore import pyqtSignal, QObject, pyqtSlot
|
||||
from qasync import asyncSlot
|
||||
from pytec.gui.model.property import Property, PropertyMeta
|
||||
@ -6,19 +5,6 @@ import asyncio
|
||||
import logging
|
||||
|
||||
|
||||
class WrappedClient(QObject, Client):
|
||||
connection_error = pyqtSignal()
|
||||
|
||||
async def _read_line(self):
|
||||
try:
|
||||
return await super()._read_line()
|
||||
except (
|
||||
TimeoutError,
|
||||
asyncio.TimeoutError, # Remove in Python 3.11
|
||||
):
|
||||
self.connection_error.emit()
|
||||
|
||||
|
||||
class Thermostat(QObject, metaclass=PropertyMeta):
|
||||
hw_rev = Property(dict)
|
||||
fan = Property(dict)
|
||||
@ -29,6 +15,7 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
||||
interval = Property(list)
|
||||
report = Property(list)
|
||||
info_box_trigger = pyqtSignal(str, str)
|
||||
connection_error = pyqtSignal()
|
||||
|
||||
def __init__(self, parent, client, update_s):
|
||||
self._update_s = update_s
|
||||
@ -53,6 +40,8 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
||||
"Encountered an error while updating parameter tree.",
|
||||
exc_info=True,
|
||||
)
|
||||
self.connection_error.emit()
|
||||
return
|
||||
_ = self.task.result()
|
||||
self.task = asyncio.create_task(self.update_params())
|
||||
await asyncio.sleep(self._update_s)
|
||||
|
@ -7,7 +7,8 @@ from pytec.gui.view.live_plot_view import LiveDataPlotter
|
||||
from pytec.gui.view.ctrl_panel import CtrlPanel
|
||||
from pytec.gui.view.info_box import InfoBox
|
||||
from pytec.gui.model.pid_autotuner import PIDAutoTuner
|
||||
from pytec.gui.model.thermostat import WrappedClient, Thermostat
|
||||
from pytec.gui.model.thermostat import Thermostat
|
||||
from pytec.aioclient import Client
|
||||
import json
|
||||
from autotune import PIDAutotuneState
|
||||
from qasync import asyncSlot, asyncClose
|
||||
@ -68,7 +69,11 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
self.hw_rev_data = None
|
||||
self.info_box = InfoBox()
|
||||
|
||||
self.client = WrappedClient(self)
|
||||
self.client = Client()
|
||||
|
||||
self.thermostat = Thermostat(
|
||||
self, self.client, self.report_refresh_spin.value()
|
||||
)
|
||||
|
||||
def handle_connection_error():
|
||||
logging.error("Client connection error, disconnecting")
|
||||
@ -78,11 +83,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
|
||||
self.bail()
|
||||
|
||||
self.client.connection_error.connect(handle_connection_error)
|
||||
|
||||
self.thermostat = Thermostat(
|
||||
self, self.client, self.report_refresh_spin.value()
|
||||
)
|
||||
self.thermostat.connection_error.connect(handle_connection_error)
|
||||
|
||||
self.autotuners = PIDAutoTuner(self, self.client, 2)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user