From 7543752af1b242d963d90c0186890594d9096cd5 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Fri, 2 Oct 2026 16:44:11 +0200 Subject: [PATCH] fix(waveform): accept x devices without a default signal --- .../widgets/plots/waveform/waveform.py | 9 +++++- tests/unit_tests/test_waveform.py | 28 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/bec_widgets/widgets/plots/waveform/waveform.py b/bec_widgets/widgets/plots/waveform/waveform.py index 9e8f986c..282a5e5a 100644 --- a/bec_widgets/widgets/plots/waveform/waveform.py +++ b/bec_widgets/widgets/plots/waveform/waveform.py @@ -711,7 +711,14 @@ class Waveform(PlotBase): def x_mode(self, value: str): self.x_axis_mode["name"] = value if value not in ["timestamp", "index", "auto"]: - self.x_axis_mode["entry"] = self.entry_validator.validate_signal(value, None) + try: + self.x_axis_mode["entry"] = self.entry_validator.validate_signal(value, None) + except ValueError: + if value not in self.entry_validator.devices: + raise + # No default signal (e.g. a device exposing only AsyncMultiSignal + # sub-signals): the x signal is chosen through signal_x. + self.x_axis_mode["entry"] = None self._current_x_device = (value, self.x_axis_mode["entry"]) self._switch_x_axis_item(mode=value) self._current_x_device = None diff --git a/tests/unit_tests/test_waveform.py b/tests/unit_tests/test_waveform.py index 4f08d98c..b7bbc593 100644 --- a/tests/unit_tests/test_waveform.py +++ b/tests/unit_tests/test_waveform.py @@ -370,6 +370,34 @@ def test_update_sync_curves(monkeypatch, qtbot, mocked_client): np.testing.assert_array_equal(recorded.get("y"), [5, 6, 7]) +def test_x_mode_accepts_a_device_without_default_signal(qtbot, mocked_client, monkeypatch): + """A device exposing only AsyncMultiSignal sub-signals has no default x signal: it can + still be chosen as x device, the signal follows through signal_x.""" + from bec_lib.device import ReadoutPriority + + from bec_widgets.tests.utils import FakeDevice + + gauss = FakeDevice("gauss", readout_priority=ReadoutPriority.ASYNC) + gauss._info["signals"] = { + f"data.{name}": { + "component_name": "data", + "signal_class": "AsyncMultiSignal", + "obj_name": f"gauss_data_{name}", + "storage_name": "gauss_data", + } + for name in ("x", "intensity") + } + monkeypatch.setitem(mocked_client.device_manager.devices, "gauss", gauss) + wf = create_widget(qtbot, Waveform, client=mocked_client) + refreshed = [] + monkeypatch.setattr(wf, "_refresh_history_curves", lambda: refreshed.append(True)) + wf.x_mode = "gauss" # SafeProperty would swallow (and log) a validation error + assert refreshed, "x_mode setter aborted after the signal validation" + assert wf.x_axis_mode["name"] == "gauss" and wf.x_axis_mode["entry"] is None + wf.signal_x = "gauss_data_x" + assert wf.x_axis_mode["entry"] == "gauss_data_x" + + def test_update_async_curves(monkeypatch, qtbot, mocked_client): """ Test that update_async_curves retrieves live data correctly and calls setData on async curves.