diff --git a/csaxs_bec/devices/smaract/smaract_ophyd.py b/csaxs_bec/devices/smaract/smaract_ophyd.py index 044d3a1..c2e4db7 100644 --- a/csaxs_bec/devices/smaract/smaract_ophyd.py +++ b/csaxs_bec/devices/smaract/smaract_ophyd.py @@ -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.""" diff --git a/tests/tests_devices/test_galil.py b/tests/tests_devices/test_galil.py index b47f271..f4f9578 100644 --- a/tests/tests_devices/test_galil.py +++ b/tests/tests_devices/test_galil.py @@ -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)