forked from M-Labs/thermostat
Integrate WrappedClient into Thermostat model
This commit is contained in:
parent
c83e6dc388
commit
047bde887e
@ -1,4 +1,3 @@
|
|||||||
from pytec.aioclient import Client
|
|
||||||
from PyQt6.QtCore import pyqtSignal, QObject, pyqtSlot
|
from PyQt6.QtCore import pyqtSignal, QObject, pyqtSlot
|
||||||
from qasync import asyncSlot
|
from qasync import asyncSlot
|
||||||
from pytec.gui.model.property import Property, PropertyMeta
|
from pytec.gui.model.property import Property, PropertyMeta
|
||||||
@ -6,17 +5,6 @@ import asyncio
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class WrappedClient(QObject, Client):
|
|
||||||
connection_error = pyqtSignal()
|
|
||||||
|
|
||||||
async def _read_line(self):
|
|
||||||
try:
|
|
||||||
return await super()._read_line()
|
|
||||||
except (Exception, TimeoutError, asyncio.exceptions.TimeoutError):
|
|
||||||
logging.error("Client connection error, disconnecting", exc_info=True)
|
|
||||||
self.connection_error.emit()
|
|
||||||
|
|
||||||
|
|
||||||
class Thermostat(QObject, metaclass=PropertyMeta):
|
class Thermostat(QObject, metaclass=PropertyMeta):
|
||||||
hw_rev = Property(dict)
|
hw_rev = Property(dict)
|
||||||
fan = Property(dict)
|
fan = Property(dict)
|
||||||
@ -27,6 +15,7 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
interval = Property(list)
|
interval = Property(list)
|
||||||
report = Property(list)
|
report = Property(list)
|
||||||
info_box_trigger = pyqtSignal(str, str)
|
info_box_trigger = pyqtSignal(str, str)
|
||||||
|
connection_error = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent, client, update_s):
|
def __init__(self, parent, client, update_s):
|
||||||
self._update_s = update_s
|
self._update_s = update_s
|
||||||
@ -49,6 +38,8 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
"Encountered an error while polling for information from Thermostat.",
|
"Encountered an error while polling for information from Thermostat.",
|
||||||
exc_info=True,
|
exc_info=True,
|
||||||
)
|
)
|
||||||
|
self.connection_error.emit()
|
||||||
|
return
|
||||||
self._update_params_task = asyncio.create_task(self.update_params())
|
self._update_params_task = asyncio.create_task(self.update_params())
|
||||||
await asyncio.sleep(self._update_s)
|
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.ctrl_panel import CtrlPanel
|
||||||
from pytec.gui.view.info_box import InfoBox
|
from pytec.gui.view.info_box import InfoBox
|
||||||
from pytec.gui.model.pid_autotuner import PIDAutoTuner
|
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
|
import json
|
||||||
from autotune import PIDAutotuneState
|
from autotune import PIDAutotuneState
|
||||||
from qasync import asyncSlot, asyncClose
|
from qasync import asyncSlot, asyncClose
|
||||||
@ -63,7 +64,11 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.hw_rev_data = None
|
self.hw_rev_data = None
|
||||||
self.info_box = InfoBox()
|
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():
|
def handle_connection_error():
|
||||||
self.info_box.display_info_box(
|
self.info_box.display_info_box(
|
||||||
@ -72,11 +77,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
self.bail()
|
self.bail()
|
||||||
|
|
||||||
self.client.connection_error.connect(handle_connection_error)
|
self.thermostat.connection_error.connect(handle_connection_error)
|
||||||
|
|
||||||
self.thermostat = Thermostat(
|
|
||||||
self, self.client, self.report_refresh_spin.value()
|
|
||||||
)
|
|
||||||
|
|
||||||
self.client.connection_error.connect(self.thermostat.timed_out)
|
self.client.connection_error.connect(self.thermostat.timed_out)
|
||||||
self.client.connection_error.connect(self.bail)
|
self.client.connection_error.connect(self.bail)
|
||||||
|
Loading…
Reference in New Issue
Block a user