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()
|
||||
|
||||
# Models
|
||||
self.thermostat = Thermostat(self, self.report_refresh_spin.value())
|
||||
self._thermostat = Thermostat(self, self.report_refresh_spin.value())
|
||||
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.autotune_state_changed.connect(self.pid_autotune_handler)
|
||||
self._autotuners = PIDAutoTuner(self, self._thermostat, 2)
|
||||
self._autotuners.autotune_state_changed.connect(self._pid_autotune_handler)
|
||||
|
||||
# Handlers for disconnections
|
||||
async def autotune_disconnect():
|
||||
for ch in range(self.NUM_CHANNELS):
|
||||
if self.autotuners.get_state(ch) != PIDAutotuneState.STATE_OFF:
|
||||
await self.autotuners.stop_pid_from_running(ch)
|
||||
self.thermostat.disconnect_cb = autotune_disconnect
|
||||
if self._autotuners.get_state(ch) != PIDAutotuneState.STATE_OFF:
|
||||
await self._autotuners.stop_pid_from_running(ch)
|
||||
self._thermostat.disconnect_cb = autotune_disconnect
|
||||
|
||||
@pyqtSlot()
|
||||
def handle_connection_error():
|
||||
self.info_box.display_info_box(
|
||||
"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
|
||||
def get_ctrl_panel_config(args):
|
||||
with open(args.param_tree, "r", encoding="utf-8") as f:
|
||||
return json.load(f)["ctrl_panel"]
|
||||
|
||||
self.ctrl_panel_view = CtrlPanel(
|
||||
self.thermostat,
|
||||
self.autotuners,
|
||||
self._ctrl_panel_view = CtrlPanel(
|
||||
self._thermostat,
|
||||
self._autotuners,
|
||||
self.info_box,
|
||||
[self.ch0_tree, self.ch1_tree],
|
||||
get_ctrl_panel_config(args),
|
||||
)
|
||||
|
||||
# Graphs
|
||||
self.channel_graphs = LiveDataPlotter(
|
||||
self.thermostat,
|
||||
self._channel_graphs = LiveDataPlotter(
|
||||
self._thermostat,
|
||||
[
|
||||
[getattr(self, f"ch{ch}_t_graph"), getattr(self, f"ch{ch}_i_graph")]
|
||||
for ch in range(self.NUM_CHANNELS)
|
||||
@ -103,32 +103,32 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
)
|
||||
|
||||
# Bottom bar menus
|
||||
self.conn_menu = ConnMenu(self.thermostat, self.connect_btn)
|
||||
self.connect_btn.setMenu(self.conn_menu)
|
||||
self._conn_menu = ConnMenu(self._thermostat, self.connect_btn)
|
||||
self.connect_btn.setMenu(self._conn_menu)
|
||||
|
||||
self.thermostat_ctrl_menu = ThermostatCtrlMenu(
|
||||
self.thermostat, self.info_box, self.style()
|
||||
self._thermostat_ctrl_menu = ThermostatCtrlMenu(
|
||||
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_settings.setMenu(self.plot_options_menu)
|
||||
self._plot_options_menu = PlotOptionsMenu(self._channel_graphs)
|
||||
self.plot_settings.setMenu(self._plot_options_menu)
|
||||
|
||||
# Status line
|
||||
self.zero_limits_warning = ZeroLimitsWarningView(
|
||||
self.thermostat, self.style(), self.limits_warning
|
||||
self._zero_limits_warning = ZeroLimitsWarningView(
|
||||
self._thermostat, self.style(), self.limits_warning
|
||||
)
|
||||
self.loading_spinner.hide()
|
||||
|
||||
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
|
||||
async def closeEvent(self, _event):
|
||||
try:
|
||||
await self.thermostat.end_session()
|
||||
self.thermostat.connection_state = ThermostatConnectionState.DISCONNECTED
|
||||
await self._thermostat.end_session()
|
||||
self._thermostat.connection_state = ThermostatConnectionState.DISCONNECTED
|
||||
except:
|
||||
pass
|
||||
|
||||
@ -145,8 +145,8 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
self.connect_btn.setText("Disconnect")
|
||||
self.status_lbl.setText(
|
||||
"Connected to Thermostat v"
|
||||
f"{self.thermostat.hw_rev['rev']['major']}."
|
||||
f"{self.thermostat.hw_rev['rev']['minor']}"
|
||||
f"{self._thermostat.hw_rev['rev']['major']}."
|
||||
f"{self._thermostat.hw_rev['rev']['minor']}"
|
||||
)
|
||||
|
||||
case ThermostatConnectionState.CONNECTING:
|
||||
@ -159,10 +159,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
self.report_box.setChecked(False)
|
||||
|
||||
@pyqtSlot(int, PIDAutotuneState)
|
||||
def pid_autotune_handler(self, _ch, _state):
|
||||
def _pid_autotune_handler(self, _ch, _state):
|
||||
ch_tuning = []
|
||||
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_RELAY_STEP_UP,
|
||||
PIDAutotuneState.STATE_RELAY_STEP_DOWN,
|
||||
@ -182,19 +182,19 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
|
||||
@asyncSlot()
|
||||
async def on_connect_btn_clicked(self):
|
||||
match self.thermostat.connection_state:
|
||||
match self._thermostat.connection_state:
|
||||
case ThermostatConnectionState.DISCONNECTED:
|
||||
self._connecting_task = asyncio.create_task(
|
||||
self.thermostat.start_session(
|
||||
host=self.conn_menu.host_set_line.text(),
|
||||
port=self.conn_menu.port_set_spin.value(),
|
||||
self._thermostat.start_session(
|
||||
host=self._conn_menu.host_set_line.text(),
|
||||
port=self._conn_menu.port_set_spin.value(),
|
||||
)
|
||||
)
|
||||
self.thermostat.connection_state = ThermostatConnectionState.CONNECTING
|
||||
self._thermostat.connection_state = ThermostatConnectionState.CONNECTING
|
||||
await self._connecting_task
|
||||
self._connecting_task = None
|
||||
self.thermostat.connection_state = ThermostatConnectionState.CONNECTED
|
||||
self.thermostat.start_watching()
|
||||
self._thermostat.connection_state = ThermostatConnectionState.CONNECTED
|
||||
self._thermostat.start_watching()
|
||||
|
||||
case ThermostatConnectionState.CONNECTING:
|
||||
self._connecting_task.cancel()
|
||||
@ -205,14 +205,14 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
self._connecting_task = None
|
||||
|
||||
case ThermostatConnectionState.CONNECTED:
|
||||
await self.thermostat.end_session()
|
||||
self.thermostat.connection_state = (
|
||||
await self._thermostat.end_session()
|
||||
self._thermostat.connection_state = (
|
||||
ThermostatConnectionState.DISCONNECTED
|
||||
)
|
||||
|
||||
@asyncSlot(int)
|
||||
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():
|
||||
@ -235,9 +235,9 @@ async def coro_main():
|
||||
|
||||
if args.connect:
|
||||
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:
|
||||
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()
|
||||
|
||||
await app_quit_event.wait()
|
||||
|
Loading…
Reference in New Issue
Block a user