From 8478cc8ff48416f505e63d3c769ae37f232d079f Mon Sep 17 00:00:00 2001 From: appel_c Date: Fri, 22 May 2026 14:52:19 +0200 Subject: [PATCH] wip fix utils to convert scan info --- debye_bec/devices/utils/utils.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/debye_bec/devices/utils/utils.py b/debye_bec/devices/utils/utils.py index 8e92287..1475961 100644 --- a/debye_bec/devices/utils/utils.py +++ b/debye_bec/devices/utils/utils.py @@ -1,8 +1,11 @@ """Utility functions for the devices.""" +from copy import deepcopy + +import numpy as np from bec_lib.devicemanager import ScanInfo from bec_server.scan_server.scans.scan_base import ScanInfo as ScanServerScanInfo -import numpy as np +from pydantic import ValidationError def fetch_scan_info(scan_info: ScanInfo) -> ScanServerScanInfo: @@ -10,4 +13,14 @@ def fetch_scan_info(scan_info: ScanInfo) -> ScanServerScanInfo: info = scan_info.msg.info if isinstance(info["positions"], list): info["positions"] = np.array(info["positions"]) - return ScanServerScanInfo.model_validate(info) + try: + msg = ScanServerScanInfo.model_validate(info) + except ValidationError: # This means we have an old scan_info object. + info = deepcopy(info) + # We need to convert a few parameters manually. + info["scan_type"] = ( + "hardware_triggered" if info["scan_type"] == "fly" else "software_triggered" + ) + msg = ScanServerScanInfo.model_validate(info) + + return msg