fix(smaract): ensure setpoint is in sync after restart #184

Merged
wakonig_k merged 1 commits from fix/smaract_init into main 2026-04-09 14:14:24 +02:00
2 changed files with 13 additions and 2 deletions
+12 -1
View File
@@ -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."""
+1 -1
View File
@@ -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)