forked from M-Labs/thermostat
State update explicitly
This commit is contained in:
parent
bddcb37a8d
commit
062094f7a8
|
@ -14,6 +14,7 @@ class ThermostatConnectionState(Enum):
|
|||
|
||||
|
||||
class Thermostat(QObject, metaclass=PropertyMeta):
|
||||
connection_state = Property(ThermostatConnectionState)
|
||||
hw_rev = Property(dict)
|
||||
fan = Property(dict)
|
||||
thermistor = Property(list)
|
||||
|
@ -23,7 +24,6 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||
report = Property(list)
|
||||
|
||||
connection_error = pyqtSignal()
|
||||
connection_state_changed = pyqtSignal(ThermostatConnectionState)
|
||||
|
||||
NUM_CHANNELS = 2
|
||||
|
||||
|
@ -37,11 +37,13 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||
self.disconnect_cb = disconnect_cb
|
||||
super().__init__(parent)
|
||||
|
||||
self.connection_state = ThermostatConnectionState.DISCONNECTED
|
||||
|
||||
async def start_session(self, host, port):
|
||||
self.connection_state_changed.emit(ThermostatConnectionState.CONNECTING)
|
||||
self.connection_state = ThermostatConnectionState.CONNECTING
|
||||
await self._client.connect(host, port)
|
||||
self.hw_rev = await self.get_hw_rev()
|
||||
self.connection_state_changed.emit(ThermostatConnectionState.CONNECTED)
|
||||
self.connection_state = ThermostatConnectionState.CONNECTED
|
||||
self.start_watching()
|
||||
|
||||
async def run(self):
|
||||
|
@ -133,7 +135,7 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||
self.disconnect_cb()
|
||||
|
||||
await self._client.disconnect()
|
||||
self.connection_state_changed.emit(ThermostatConnectionState.DISCONNECTED)
|
||||
self.connection_state = ThermostatConnectionState.DISCONNECTED
|
||||
|
||||
async def set_ipv4(self, ipv4):
|
||||
await self._client.set_param("ipv4", ipv4)
|
||||
|
|
|
@ -8,7 +8,7 @@ class ConnMenu(QtWidgets.QMenu):
|
|||
super().__init__()
|
||||
self._thermostat = thermostat
|
||||
self._connect_btn = connect_btn
|
||||
self._thermostat.connection_state_changed.connect(
|
||||
self._thermostat.connection_state_update.connect(
|
||||
self.thermostat_state_change_handler
|
||||
)
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class LiveDataPlotter(QObject):
|
|||
|
||||
self._thermostat.report_update.connect(self.update_report)
|
||||
self._thermostat.pid_update.connect(self.update_pid)
|
||||
self._thermostat.connection_state_changed.connect(
|
||||
self._thermostat.connection_state_update.connect(
|
||||
self.thermostat_state_change_handler
|
||||
)
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class ThermostatCtrlMenu(QtWidgets.QMenu):
|
|||
|
||||
self.hw_rev_data = dict()
|
||||
self._thermostat.hw_rev_update.connect(self.hw_rev)
|
||||
self._thermostat.connection_state_changed.connect(
|
||||
self._thermostat.connection_state_update.connect(
|
||||
self.thermostat_state_change_handler
|
||||
)
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
# Models
|
||||
self.thermostat = Thermostat(self, self.report_refresh_spin.value())
|
||||
self._connecting_task = None
|
||||
self.thermostat.connection_state_changed.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)
|
||||
|
|
Loading…
Reference in New Issue