From b492face878a9ad27d9e03c64c135582d0aa85d6 Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 31 Jul 2026 12:21:09 +0200 Subject: [PATCH] fix: use macros from dispatch --- .../default/beamline_dispatch.py | 2 +- src/aare/beamline_dispatch/protocols.py | 2 +- .../simulated/beamline_dispatch.py | 8 +++++-- .../x10sa/beamline_dispatch.py | 15 +++++++++---- src/aare/devices/bec_worker.py | 22 +++++++++---------- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/aare/beamline_dispatch/default/beamline_dispatch.py b/src/aare/beamline_dispatch/default/beamline_dispatch.py index ea31ff95..64daae3a 100644 --- a/src/aare/beamline_dispatch/default/beamline_dispatch.py +++ b/src/aare/beamline_dispatch/default/beamline_dispatch.py @@ -1,6 +1,6 @@ import os -from aare.beamline_dispatch.protocols import AuthDispatch, BeamlineDispatch, BecMacros +from aare.beamline_dispatch.protocols import AuthDispatch, BeamlineDispatch class DefaultAuthDispatch(AuthDispatch): diff --git a/src/aare/beamline_dispatch/protocols.py b/src/aare/beamline_dispatch/protocols.py index 9074e2ef..d0675a7a 100644 --- a/src/aare/beamline_dispatch/protocols.py +++ b/src/aare/beamline_dispatch/protocols.py @@ -10,7 +10,7 @@ class AuthDispatch(ABC): class BecMacros(ABC): @staticmethod @abstractmethod - def save_and_reload(): ... + def save_and_reload() -> tuple[Any, Any]: ... @staticmethod @abstractmethod def save_current_position(device, position, axis=None, force=False, max_delta=0.5) -> None: ... diff --git a/src/aare/beamline_dispatch/simulated/beamline_dispatch.py b/src/aare/beamline_dispatch/simulated/beamline_dispatch.py index 88429d77..59fcbd14 100644 --- a/src/aare/beamline_dispatch/simulated/beamline_dispatch.py +++ b/src/aare/beamline_dispatch/simulated/beamline_dispatch.py @@ -11,11 +11,15 @@ class SimulatedAuthDispatch(AuthDispatch): class SimulatedBecMacros(BecMacros): @staticmethod - def save_and_reload(): ... + def save_and_reload() -> tuple[Any, Any]: + return (None, None) + @staticmethod def save_current_position(device, position, axis=None, force=False, max_delta=0.5) -> None: ... @staticmethod - def init_beamline_environment() -> tuple[Any, Any]: ... + def init_beamline_environment() -> tuple[Any, Any]: + return (None, None) + @staticmethod def bl_energy(energy_ev, move_gap=True, mono_scan=True, plot=True): ... @staticmethod diff --git a/src/aare/beamline_dispatch/x10sa/beamline_dispatch.py b/src/aare/beamline_dispatch/x10sa/beamline_dispatch.py index a6647caf..380513cb 100644 --- a/src/aare/beamline_dispatch/x10sa/beamline_dispatch.py +++ b/src/aare/beamline_dispatch/x10sa/beamline_dispatch.py @@ -6,9 +6,16 @@ from aare.beamline_dispatch.protocols import BecMacros class X10SaBecMacros(BecMacros): def __init__(self) -> None: - from pxii_bec.macros.build_devices import save_and_reload, save_current_position - from pxii_bec.macros.init_beamline import init_beamline_environment - from pxii_bec.macros.pxii_energy import bl_energy, get_current_energy, mono_pitch_scan + from pxii_bec.macros.build_devices import ( # type: ignore + save_and_reload, + save_current_position, + ) + from pxii_bec.macros.init_beamline import init_beamline_environment # type: ignore + from pxii_bec.macros.pxii_energy import ( # type: ignore + bl_energy, + get_current_energy, + mono_pitch_scan, + ) self.save_and_reload = save_and_reload self.save_current_position = save_current_position @@ -18,7 +25,7 @@ class X10SaBecMacros(BecMacros): self.mono_pitch_scan = mono_pitch_scan @staticmethod - def save_and_reload(): ... + def save_and_reload() -> tuple[Any, Any]: ... @staticmethod def save_current_position(device, position, axis=None, force=False, max_delta=0.5) -> None: ... @staticmethod diff --git a/src/aare/devices/bec_worker.py b/src/aare/devices/bec_worker.py index 8e1fe4e1..f6649bbe 100644 --- a/src/aare/devices/bec_worker.py +++ b/src/aare/devices/bec_worker.py @@ -84,7 +84,7 @@ class BECClientWorker: print(self.dev.keys()) self.scans = self.client.scans self.macros = self.dispatch.bec_macros - self._load_user_macros() + self.client.macros._load_user_macros() print(self._list_all_macros()) self.helper = FrontendProcedureHelper(self.client.connector) self._set_scilog_tags() @@ -301,7 +301,7 @@ class BECClientWorker: self._raise_bec_error(e, operation="list_all_user_macros") def _list_all_macros(self): - result = self.macros.list_user_macros() + result = self.client.macros.list_user_macros() if result is None: return [] return result @@ -354,7 +354,7 @@ class BECClientWorker: def mono_pitch_scan_runner(self, plot: bool = False): try: - mono_pitch_scan(plot) + self.macros.mono_pitch_scan(plot) except Exception as e: self._raise_bec_error(e, operation="mono_pitch_scan", tags=["mono_pitch_scan"]) if self.beamline is MXBeamline.X06DA: @@ -371,7 +371,7 @@ class BECClientWorker: def check_current_energy(self): """Get the current energy from the BEC in eV""" - energy_ev = get_current_energy() + energy_ev = self.macros.get_current_energy() energy_kev = energy_ev / 1000 return energy_kev @@ -380,7 +380,7 @@ class BECClientWorker: logger.info(f"Current energy: {current_energy:.1f} eV") logger.info(f"Change energy requested: from {current_energy:.1f} to {value:.1f} eV") try: - bl_energy(value, move_gap=False, mono_scan=True, plot=plot) + self.macros.bl_energy(value, move_gap=False, mono_scan=True, plot=plot) except Exception as e: self._raise_bec_error( e, @@ -496,20 +496,20 @@ class BECClientWorker: ) def save_current_bs_pos(self): - save_current_position(self.dev.bs_z, "safe") + self.macros.save_current_position(self.dev.bs_z, "safe") def save_current_collimator_pos(self): - save_current_position(self.dev.coll_y, "work") + self.macros.save_current_position(self.dev.coll_y, "work") def save_current_aerotech_position(self): - save_current_position(self.dev.aerotech, "work", axis="x") - save_current_position(self.dev.aerotech, "work", axis="y") - save_current_position(self.dev.aerotech, "work", axis="z") + self.macros.save_current_position(self.dev.aerotech, "work", axis="x") + self.macros.save_current_position(self.dev.aerotech, "work", axis="y") + self.macros.save_current_position(self.dev.aerotech, "work", axis="z") self.save_config_and_reload_devices() def save_config_and_reload_devices(self): - self.position_devices, self.planner = save_and_reload() + self.position_devices, self.planner = self.macros.save_and_reload() @property def zoom(self):