forked from M-Labs/thermostat
tec_qt: Private everything possible
This commit is contained in:
parent
2334a922f7
commit
29221ce570
@ -59,43 +59,43 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.info_box = InfoBox()
|
self.info_box = InfoBox()
|
||||||
|
|
||||||
# Models
|
# Models
|
||||||
self.thermostat = Thermostat(self, self.report_refresh_spin.value())
|
self._thermostat = Thermostat(self, self.report_refresh_spin.value())
|
||||||
self._connecting_task = None
|
self._connecting_task = None
|
||||||
self.thermostat.connection_state_update.connect(self._on_connection_changed)
|
self._thermostat.connection_state_update.connect(self._on_connection_changed)
|
||||||
|
|
||||||
self.autotuners = PIDAutoTuner(self, self.thermostat, 2)
|
self._autotuners = PIDAutoTuner(self, self._thermostat, 2)
|
||||||
self.autotuners.autotune_state_changed.connect(self.pid_autotune_handler)
|
self._autotuners.autotune_state_changed.connect(self._pid_autotune_handler)
|
||||||
|
|
||||||
# Handlers for disconnections
|
# Handlers for disconnections
|
||||||
async def autotune_disconnect():
|
async def autotune_disconnect():
|
||||||
for ch in range(self.NUM_CHANNELS):
|
for ch in range(self.NUM_CHANNELS):
|
||||||
if self.autotuners.get_state(ch) != PIDAutotuneState.STATE_OFF:
|
if self._autotuners.get_state(ch) != PIDAutotuneState.STATE_OFF:
|
||||||
await self.autotuners.stop_pid_from_running(ch)
|
await self._autotuners.stop_pid_from_running(ch)
|
||||||
self.thermostat.disconnect_cb = autotune_disconnect
|
self._thermostat.disconnect_cb = autotune_disconnect
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def handle_connection_error():
|
def handle_connection_error():
|
||||||
self.info_box.display_info_box(
|
self.info_box.display_info_box(
|
||||||
"Connection Error", "Thermostat connection lost. Is it unplugged?"
|
"Connection Error", "Thermostat connection lost. Is it unplugged?"
|
||||||
)
|
)
|
||||||
self.thermostat.connection_error.connect(handle_connection_error)
|
self._thermostat.connection_error.connect(handle_connection_error)
|
||||||
|
|
||||||
# Control Panel
|
# Control Panel
|
||||||
def get_ctrl_panel_config(args):
|
def get_ctrl_panel_config(args):
|
||||||
with open(args.param_tree, "r", encoding="utf-8") as f:
|
with open(args.param_tree, "r", encoding="utf-8") as f:
|
||||||
return json.load(f)["ctrl_panel"]
|
return json.load(f)["ctrl_panel"]
|
||||||
|
|
||||||
self.ctrl_panel_view = CtrlPanel(
|
self._ctrl_panel_view = CtrlPanel(
|
||||||
self.thermostat,
|
self._thermostat,
|
||||||
self.autotuners,
|
self._autotuners,
|
||||||
self.info_box,
|
self.info_box,
|
||||||
[self.ch0_tree, self.ch1_tree],
|
[self.ch0_tree, self.ch1_tree],
|
||||||
get_ctrl_panel_config(args),
|
get_ctrl_panel_config(args),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Graphs
|
# Graphs
|
||||||
self.channel_graphs = LiveDataPlotter(
|
self._channel_graphs = LiveDataPlotter(
|
||||||
self.thermostat,
|
self._thermostat,
|
||||||
[
|
[
|
||||||
[getattr(self, f"ch{ch}_t_graph"), getattr(self, f"ch{ch}_i_graph")]
|
[getattr(self, f"ch{ch}_t_graph"), getattr(self, f"ch{ch}_i_graph")]
|
||||||
for ch in range(self.NUM_CHANNELS)
|
for ch in range(self.NUM_CHANNELS)
|
||||||
@ -103,32 +103,32 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Bottom bar menus
|
# Bottom bar menus
|
||||||
self.conn_menu = ConnMenu(self.thermostat, self.connect_btn)
|
self._conn_menu = ConnMenu(self._thermostat, self.connect_btn)
|
||||||
self.connect_btn.setMenu(self.conn_menu)
|
self.connect_btn.setMenu(self._conn_menu)
|
||||||
|
|
||||||
self.thermostat_ctrl_menu = ThermostatCtrlMenu(
|
self._thermostat_ctrl_menu = ThermostatCtrlMenu(
|
||||||
self.thermostat, self.info_box, self.style()
|
self._thermostat, self.info_box, self.style()
|
||||||
)
|
)
|
||||||
self.thermostat_settings.setMenu(self.thermostat_ctrl_menu)
|
self.thermostat_settings.setMenu(self._thermostat_ctrl_menu)
|
||||||
|
|
||||||
self.plot_options_menu = PlotOptionsMenu(self.channel_graphs)
|
self._plot_options_menu = PlotOptionsMenu(self._channel_graphs)
|
||||||
self.plot_settings.setMenu(self.plot_options_menu)
|
self.plot_settings.setMenu(self._plot_options_menu)
|
||||||
|
|
||||||
# Status line
|
# Status line
|
||||||
self.zero_limits_warning = ZeroLimitsWarningView(
|
self._zero_limits_warning = ZeroLimitsWarningView(
|
||||||
self.thermostat, self.style(), self.limits_warning
|
self._thermostat, self.style(), self.limits_warning
|
||||||
)
|
)
|
||||||
self.loading_spinner.hide()
|
self.loading_spinner.hide()
|
||||||
|
|
||||||
self.report_apply_btn.clicked.connect(
|
self.report_apply_btn.clicked.connect(
|
||||||
lambda: self.thermostat.set_update_s(self.report_refresh_spin.value())
|
lambda: self._thermostat.set_update_s(self.report_refresh_spin.value())
|
||||||
)
|
)
|
||||||
|
|
||||||
@asyncClose
|
@asyncClose
|
||||||
async def closeEvent(self, _event):
|
async def closeEvent(self, _event):
|
||||||
try:
|
try:
|
||||||
await self.thermostat.end_session()
|
await self._thermostat.end_session()
|
||||||
self.thermostat.connection_state = ThermostatConnectionState.DISCONNECTED
|
self._thermostat.connection_state = ThermostatConnectionState.DISCONNECTED
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -145,8 +145,8 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.connect_btn.setText("Disconnect")
|
self.connect_btn.setText("Disconnect")
|
||||||
self.status_lbl.setText(
|
self.status_lbl.setText(
|
||||||
"Connected to Thermostat v"
|
"Connected to Thermostat v"
|
||||||
f"{self.thermostat.hw_rev['rev']['major']}."
|
f"{self._thermostat.hw_rev['rev']['major']}."
|
||||||
f"{self.thermostat.hw_rev['rev']['minor']}"
|
f"{self._thermostat.hw_rev['rev']['minor']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
case ThermostatConnectionState.CONNECTING:
|
case ThermostatConnectionState.CONNECTING:
|
||||||
@ -159,10 +159,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.report_box.setChecked(False)
|
self.report_box.setChecked(False)
|
||||||
|
|
||||||
@pyqtSlot(int, PIDAutotuneState)
|
@pyqtSlot(int, PIDAutotuneState)
|
||||||
def pid_autotune_handler(self, _ch, _state):
|
def _pid_autotune_handler(self, _ch, _state):
|
||||||
ch_tuning = []
|
ch_tuning = []
|
||||||
for ch in range(self.NUM_CHANNELS):
|
for ch in range(self.NUM_CHANNELS):
|
||||||
if self.autotuners.get_state(ch) in {
|
if self._autotuners.get_state(ch) in {
|
||||||
PIDAutotuneState.STATE_READY,
|
PIDAutotuneState.STATE_READY,
|
||||||
PIDAutotuneState.STATE_RELAY_STEP_UP,
|
PIDAutotuneState.STATE_RELAY_STEP_UP,
|
||||||
PIDAutotuneState.STATE_RELAY_STEP_DOWN,
|
PIDAutotuneState.STATE_RELAY_STEP_DOWN,
|
||||||
@ -182,19 +182,19 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
@asyncSlot()
|
@asyncSlot()
|
||||||
async def on_connect_btn_clicked(self):
|
async def on_connect_btn_clicked(self):
|
||||||
match self.thermostat.connection_state:
|
match self._thermostat.connection_state:
|
||||||
case ThermostatConnectionState.DISCONNECTED:
|
case ThermostatConnectionState.DISCONNECTED:
|
||||||
self._connecting_task = asyncio.create_task(
|
self._connecting_task = asyncio.create_task(
|
||||||
self.thermostat.start_session(
|
self._thermostat.start_session(
|
||||||
host=self.conn_menu.host_set_line.text(),
|
host=self._conn_menu.host_set_line.text(),
|
||||||
port=self.conn_menu.port_set_spin.value(),
|
port=self._conn_menu.port_set_spin.value(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.thermostat.connection_state = ThermostatConnectionState.CONNECTING
|
self._thermostat.connection_state = ThermostatConnectionState.CONNECTING
|
||||||
await self._connecting_task
|
await self._connecting_task
|
||||||
self._connecting_task = None
|
self._connecting_task = None
|
||||||
self.thermostat.connection_state = ThermostatConnectionState.CONNECTED
|
self._thermostat.connection_state = ThermostatConnectionState.CONNECTED
|
||||||
self.thermostat.start_watching()
|
self._thermostat.start_watching()
|
||||||
|
|
||||||
case ThermostatConnectionState.CONNECTING:
|
case ThermostatConnectionState.CONNECTING:
|
||||||
self._connecting_task.cancel()
|
self._connecting_task.cancel()
|
||||||
@ -205,14 +205,14 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self._connecting_task = None
|
self._connecting_task = None
|
||||||
|
|
||||||
case ThermostatConnectionState.CONNECTED:
|
case ThermostatConnectionState.CONNECTED:
|
||||||
await self.thermostat.end_session()
|
await self._thermostat.end_session()
|
||||||
self.thermostat.connection_state = (
|
self._thermostat.connection_state = (
|
||||||
ThermostatConnectionState.DISCONNECTED
|
ThermostatConnectionState.DISCONNECTED
|
||||||
)
|
)
|
||||||
|
|
||||||
@asyncSlot(int)
|
@asyncSlot(int)
|
||||||
async def on_report_box_stateChanged(self, enabled):
|
async def on_report_box_stateChanged(self, enabled):
|
||||||
await self.thermostat.set_report_mode(enabled)
|
await self._thermostat.set_report_mode(enabled)
|
||||||
|
|
||||||
|
|
||||||
async def coro_main():
|
async def coro_main():
|
||||||
@ -235,9 +235,9 @@ async def coro_main():
|
|||||||
|
|
||||||
if args.connect:
|
if args.connect:
|
||||||
if args.HOST:
|
if args.HOST:
|
||||||
main_window.conn_menu.host_set_line.setText(args.HOST)
|
main_window._conn_menu.host_set_line.setText(args.HOST)
|
||||||
if args.PORT:
|
if args.PORT:
|
||||||
main_window.conn_menu.port_set_spin.setValue(int(args.PORT))
|
main_window._conn_menu.port_set_spin.setValue(int(args.PORT))
|
||||||
main_window.connect_btn.click()
|
main_window.connect_btn.click()
|
||||||
|
|
||||||
await app_quit_event.wait()
|
await app_quit_event.wait()
|
||||||
|
Loading…
Reference in New Issue
Block a user