Refactor repeated stuff

This commit is contained in:
atse 2024-08-28 10:24:25 +08:00
parent c25c49d8c1
commit 029866ee22
1 changed files with 12 additions and 14 deletions

View File

@ -124,14 +124,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")
self.status_lbl.setText(
"Connected to Thermostat v"
@ -142,16 +148,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")