refactor(undulator): raise for setpoint if undulator is operator controlled

This commit is contained in:
2025-08-07 12:52:35 +02:00
parent eb6b6dae8f
commit db72a81d91
2 changed files with 47 additions and 7 deletions

View File

@@ -24,7 +24,7 @@ class UNDULATORCONTROL(int, enum.Enum):
BEAMLINE = 1
class UndulatorEpicsSignal(EpicsSignal):
class UndulatorSetointSignal(EpicsSignal):
"""
SLS Undulator setpoint control
"""
@@ -45,9 +45,43 @@ class UndulatorEpicsSignal(EpicsSignal):
If the undulator is operator controlled, it will not move.
"""
if self.parent.select_control.get() == UNDULATORCONTROL.OPERATOR.value:
raise PermissionError(
raise PermissionError("Undulator is operator controlled!")
return super().put(
value,
force=force,
connection_timeout=connection_timeout,
callback=callback,
use_complete=use_complete,
timeout=timeout,
**kwargs,
)
class UndulatorStopSignal(EpicsSignal):
"""
SLS Undulator setpoint control
"""
def put(
self,
value,
force=False,
connection_timeout=DEFAULT_CONNECTION_TIMEOUT,
callback=None,
use_complete=None,
timeout=DEFAULT_WRITE_TIMEOUT,
**kwargs,
):
"""
Put a value to the setpoint PV.
If the undulator is operator controlled, it will not move.
"""
if self.parent.select_control.get() == UNDULATORCONTROL.OPERATOR.value:
logger.error(
f"Cannot use put for signal {self.name}; Undulator is operator controlled!"
)
return None
return super().put(
value,
force=force,
@@ -64,10 +98,10 @@ class UndulatorGap(PVPositioner):
SLS Undulator gap control
"""
setpoint = Cpt(UndulatorEpicsSignal, suffix="GAP-SP")
readback = Cpt(EpicsSignal, suffix="GAP-RBV", kind="hinted", auto_monitor=True)
setpoint = Cpt(UndulatorSetointSignal, suffix="GAP-SP")
readback = Cpt(EpicsSignalRO, suffix="GAP-RBV", kind="hinted", auto_monitor=True)
stop_signal = Cpt(UndulatorEpicsSignal, suffix="STOP")
stop_signal = Cpt(UndulatorStopSignal, suffix="STOP")
done = Cpt(EpicsSignalRO, suffix="DONE", auto_monitor=True)
select_control = Cpt(EpicsSignalRO, suffix="SCTRL", auto_monitor=True)

View File

@@ -52,11 +52,17 @@ def test_undulator_raises_when_disabled(mock_undulator):
with pytest.raises(PermissionError) as e:
mock_undulator.move(5)
assert e.match("Undulator is operator controlled!")
with pytest.raises(PermissionError) as e:
mock_undulator.setpoint.put(5)
assert e.match("Undulator is operator controlled!")
def test_undulator_stop_call(mock_undulator):
mock_undulator.select_control._read_pv.mock_data = 1
mock_undulator.stop_signal._read_pv.mock_data = 0
mock_undulator.stop()
assert mock_undulator.stop_signal.get() == 1
mock_undulator.stop_signal._read_pv.mock_data = 0
mock_undulator.select_control._read_pv.mock_data = 0
with pytest.raises(PermissionError) as e:
mock_undulator.stop()
mock_undulator.stop()
assert mock_undulator.stop_signal.get() == 0