Skip to content

Commit 9151497

Browse files
updates that aren't working
1 parent 36805b1 commit 9151497

File tree

6 files changed

+57
-43
lines changed

6 files changed

+57
-43
lines changed

src/ibex_bluesky_core/devices/dae/_period_settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from xml.etree.ElementTree import tostring
88

99
from bluesky.protocols import Locatable, Location, Movable
10-
from ophyd_async.core import AsyncStatus, Device, SignalRW
10+
from ophyd_async.core import AsyncStatus, StandardReadable, SignalRW
1111

1212
from ibex_bluesky_core.devices import (
1313
isis_epics_signal_rw,
@@ -116,7 +116,7 @@ def _convert_period_settings_to_xml(current_xml: str, value: DaePeriodSettingsDa
116116
return tostring(root, encoding="unicode")
117117

118118

119-
class DaePeriodSettings(Device, Locatable[DaePeriodSettingsData], Movable[DaePeriodSettingsData]):
119+
class DaePeriodSettings(StandardReadable, Locatable[DaePeriodSettingsData], Movable[DaePeriodSettingsData]):
120120
"""Subdevice for the DAE hardware period settings."""
121121

122122
def __init__(self, dae_prefix: str, name: str = "") -> None:

src/ibex_bluesky_core/devices/dae/_tcb_settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from xml.etree.ElementTree import tostring
88

99
from bluesky.protocols import Locatable, Location, Movable
10-
from ophyd_async.core import AsyncStatus, Device, SignalRW
10+
from ophyd_async.core import AsyncStatus, SignalRW, StandardReadable
1111

1212
from ibex_bluesky_core.devices import (
1313
compress_and_hex,
@@ -120,7 +120,7 @@ def _convert_tcb_settings_to_xml(current_xml: str, settings: DaeTCBSettingsData)
120120
return tostring(root, encoding="unicode")
121121

122122

123-
class DaeTCBSettings(Device, Locatable[DaeTCBSettingsData], Movable[DaeTCBSettingsData]):
123+
class DaeTCBSettings(StandardReadable, Locatable[DaeTCBSettingsData], Movable[DaeTCBSettingsData]):
124124
"""Subdevice for the DAE time channel settings."""
125125

126126
def __init__(self, dae_prefix: str, name: str = "") -> None:

src/ibex_bluesky_core/plan_stubs/dae_table_wrapper.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
from bluesky.utils import Msg
88
from ophyd_async.plan_stubs import ensure_connected
99

10-
from ibex_bluesky_core.devices.dae import Dae
10+
from ibex_bluesky_core.devices.dae import Dae, DaeSettingsData
1111

1212

13-
def with_dae_tables(plan: Generator[Msg, None, None], dae: Dae) -> Generator[Msg, None, None]:
13+
def with_dae_tables(plan: Generator[Msg, None, None],
14+
dae: Dae,
15+
new_settings: DaeSettingsData) -> Generator[Msg, None, None]:
1416
"""Wrap a plan with temporary modification to DAE Settings.
1517
1618
Args:
@@ -30,10 +32,8 @@ def _inner() -> Generator[Msg, None, None]:
3032
nonlocal original_dae_setting
3133
original_dae_setting = yield from bps.rd(dae.dae_settings)
3234

33-
yield from plan
35+
yield from bps.mv(dae.dae_settings, new_settings)
3436

35-
def _onexit() -> Generator[Msg, None, None]:
36-
nonlocal original_dae_setting
37-
yield from bps.mv(dae.dae_settings, original_dae_setting)
37+
yield from plan
3838

39-
return (yield from bpp.finalize_wrapper(_inner(), _onexit()))
39+
return (yield from bpp.finalize_wrapper(_inner(), bps.mv(dae.dae_settings, original_dae_setting)))
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
"""Wrap a plan with temporary modification to Periods Settings."""
22

3+
import copy
34
from collections.abc import Generator
45

56
import bluesky.plan_stubs as bps
67
import bluesky.preprocessors as bpp
78
from bluesky.utils import Msg
89
from ophyd_async.plan_stubs import ensure_connected
10+
from ibex_bluesky_core.devices.dae import DaePeriodSettings, Dae
911

10-
from ibex_bluesky_core.devices.dae import Dae
1112

12-
13-
def with_num_periods(plan: Generator[Msg, None, None], dae: Dae) -> Generator[Msg, None, None]:
13+
def with_num_periods(
14+
plan: Generator[Msg, None, None],
15+
dae: Dae,
16+
number_of_periods: int) -> Generator[Msg, None, None]:
1417
"""Wrap a plan with temporary modification to Periods Settings.
1518
1619
Args:
@@ -22,18 +25,16 @@ def with_num_periods(plan: Generator[Msg, None, None], dae: Dae) -> Generator[Ms
2225
settings afterwards.
2326
2427
"""
25-
yield from ensure_connected(dae)
2628

2729
original_num_periods = None
2830

2931
def _inner() -> Generator[Msg, None, None]:
32+
yield from ensure_connected(dae)
3033
nonlocal original_num_periods
3134
original_num_periods = yield from bps.rd(dae.number_of_periods)
3235

33-
yield from plan
36+
yield from bps.mv(dae.number_of_periods, number_of_periods)
3437

35-
def _onexit() -> Generator[Msg, None, None]:
36-
nonlocal original_num_periods
37-
yield from bps.mv(dae.number_of_periods, original_num_periods)
38+
yield from plan
3839

39-
return (yield from bpp.finalize_wrapper(_inner(), _onexit()))
40+
return (yield from bpp.finalize_wrapper(_inner(), bps.mv(dae.number_of_periods, original_num_periods)))

src/ibex_bluesky_core/plan_stubs/time_channels_wrapper.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
from bluesky.utils import Msg
88
from ophyd_async.plan_stubs import ensure_connected
99

10-
from ibex_bluesky_core.devices.dae import Dae
1110

11+
from ibex_bluesky_core.devices.dae import Dae, DaeTCBSettingsData
1212

13-
def with_time_channels(plan: Generator[Msg, None, None], dae: Dae) -> Generator[Msg, None, None]:
13+
14+
def with_time_channels(plan: Generator[Msg, None, None],
15+
dae: Dae,
16+
new_tcb_settings: DaeTCBSettingsData) -> Generator[Msg, None, None]:
1417
"""Wrap a plan with temporary modification to Time Channel Settings.
1518
1619
Args:
@@ -28,12 +31,10 @@ def with_time_channels(plan: Generator[Msg, None, None], dae: Dae) -> Generator[
2831

2932
def _inner() -> Generator[Msg, None, None]:
3033
nonlocal original_time_channels
31-
original_time_channels = yield from bps.rd(dae.tcb_settings) # type: ignore
34+
original_time_channels = yield from bps.rd(dae.tcb_settings)
3235

33-
yield from plan
36+
yield from bps.mv(dae.tcb_settings, new_tcb_settings)
3437

35-
def _onexit() -> Generator[Msg, None, None]:
36-
nonlocal original_time_channels
37-
yield from bps.mv(dae.tcb_settings, original_time_channels)
38+
yield from plan
3839

39-
return (yield from bpp.finalize_wrapper(_inner(), _onexit()))
40+
return (yield from bpp.finalize_wrapper(_inner(), bps.mv(dae.tcb_settings, original_time_channels)))

tests/devices/test_dae.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,28 +1028,39 @@ def test_dae_repr():
10281028
assert repr(Dae(prefix="foo", name="bar")) == "Dae(name=bar, prefix=foo)"
10291029

10301030

1031-
async def test_num_periods_wrapper(dae: Dae, RE: RunEngine):
1031+
def test_num_periods_wrapper(dae: Dae, RE: RunEngine):
10321032
original_settings = 4
1033-
modified_settings = 7
10341033

1035-
await dae.number_of_periods.set(original_settings)
1034+
# await dae.number_of_periods.set(original_settings)
1035+
set_mock_value(dae.number_of_periods.signal, original_settings)
10361036

1037-
def _dummy_plan_which_sets_periods(dae):
1038-
yield from bps.mv(dae.number_of_periods, modified_settings)
1037+
# t = await dae.number_of_periods.signal.get_value()
10391038

1040-
current = yield from bps.rd(dae.number_of_periods)
1041-
assert current == 7
1039+
# def _dummy_plan_which_sets_periods(dae):
1040+
# current = yield from bps.rd(dae.number_of_periods)
1041+
# print("Current number of periods:", current)
10421042

1043-
with patch("ibex_bluesky_core.plan_stubs.num_periods_wrapper.ensure_connected"):
1044-
RE(
1045-
with_num_periods(
1046-
_dummy_plan_which_sets_periods(dae),
1047-
dae=dae, # type: ignore
1048-
)
1043+
# assert current == 80
1044+
1045+
#with patch("ibex_bluesky_core.plan_stubs.num_periods_wrapper.ensure_connected"):
1046+
# This is needed for the DaeCheckingSignal
1047+
# set_mock_value(dae.number_of_periods.signal, 80)
1048+
1049+
RE(
1050+
with_num_periods(
1051+
bps.null(),
1052+
dae=dae, # type: ignore
1053+
number_of_periods = 80,
10491054
)
1055+
)
1056+
10501057

1051-
result = await dae.number_of_periods.read()
1052-
assert result["DAE-number_of_periods-signal"]["value"] == original_settings
1058+
mock_set = get_mock_put(dae.number_of_periods.signal)
1059+
1060+
mock_set.assert_called_with(80)
1061+
mock_set.assert_called_with(original_settings)
1062+
1063+
10531064

10541065

10551066
def test_time_channels_wrapper(dae: Dae, RE: RunEngine):
@@ -1081,6 +1092,7 @@ def _dummy_plan_which_sets_time_units(dae):
10811092
assert after.time_unit == expected_time_units
10821093

10831094

1095+
10841096
def test_dae_table_wrapper(dae: Dae, RE: RunEngine):
10851097
original_settings = initial_dae_settings
10861098
modified_settings = DaeSettingsData(

0 commit comments

Comments
 (0)