fix(smaract): ensure setpoint is in sync after restart #184
@@ -43,7 +43,10 @@ class SmaractReadbackSignal(SmaractSignalRO):
|
||||
|
||||
|
||||
class SmaractSetpointSignal(SmaractSignalBase):
|
||||
setpoint = 0
|
||||
|
||||
def __init__(self, signal_name, **kwargs):
|
||||
super().__init__(signal_name, **kwargs)
|
||||
self.setpoint = 0
|
||||
|
||||
@threadlocked
|
||||
def _socket_get(self):
|
||||
@@ -156,6 +159,14 @@ class SmaractMotor(Device, PositionerBase):
|
||||
|
||||
def wait_for_connection(self, timeout: float = 30.0) -> bool:
|
||||
self.controller.on(timeout=timeout)
|
||||
self._update_setpoint_from_readback()
|
||||
|
||||
def _update_setpoint_from_readback(self):
|
||||
"""
|
||||
The setpoint is only stored locally. After a restart,
|
||||
we need to update it to match the current readback value.
|
||||
"""
|
||||
self.user_setpoint.setpoint = self.readback.get()
|
||||
|
||||
def destroy(self):
|
||||
"""Make sure to turn off the controller socket on destroy."""
|
||||
|
||||
@@ -217,7 +217,7 @@ def test_wait_for_connection_called(dm_with_devices):
|
||||
}
|
||||
motor = motor_cls(*args, **kwargs)
|
||||
with mock.patch.object(motor.controller, "on") as mock_on:
|
||||
|
||||
motor.controller.get_position = mock.MagicMock(return_value=0)
|
||||
motor.wait_for_connection(timeout=5.0)
|
||||
assert mock_on.call_args_list[-1] == mock.call(timeout=5.0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user