Refactor repeated stuff

This commit is contained in:
atse 2024-08-28 10:24:25 +08:00
parent 94eb331c96
commit ac9ddc92a6

View File

@ -133,14 +133,20 @@ class MainWindow(QtWidgets.QMainWindow):
@asyncSlot(ThermostatConnectionState)
async def _on_connection_changed(self, result):
self.graph_group.setEnabled(result == ThermostatConnectionState.CONNECTED)
self.report_group.setEnabled(result == ThermostatConnectionState.CONNECTED)
self.thermostat_settings.setEnabled(
result == ThermostatConnectionState.CONNECTED
)
self.conn_menu.host_set_line.setEnabled(
result != ThermostatConnectionState.DISCONNECTED
)
self.conn_menu.port_set_spin.setEnabled(
result != ThermostatConnectionState.DISCONNECTED
)
match result:
case ThermostatConnectionState.CONNECTED:
self.graph_group.setEnabled(True)
self.report_group.setEnabled(True)
self.thermostat_settings.setEnabled(True)
self.conn_menu.host_set_line.setEnabled(False)
self.conn_menu.port_set_spin.setEnabled(False)
self.connect_btn.setText("Disconnect")
hw_rev_d = await self.thermostat.get_hw_rev()
self.status_lbl.setText(
@ -150,16 +156,8 @@ class MainWindow(QtWidgets.QMainWindow):
case ThermostatConnectionState.CONNECTING:
self.status_lbl.setText("Connecting...")
self.connect_btn.setText("Stop")
self.conn_menu.host_set_line.setEnabled(False)
self.conn_menu.port_set_spin.setEnabled(False)
case ThermostatConnectionState.DISCONNECTED:
self.graph_group.setEnabled(False)
self.report_group.setEnabled(False)
self.thermostat_settings.setEnabled(False)
self.conn_menu.host_set_line.setEnabled(True)
self.conn_menu.port_set_spin.setEnabled(True)
self.connect_btn.setText("Connect")
self.status_lbl.setText("Disconnected")