Skip to content

Commit

Permalink
(#117) (#45) only update elapsed time in status if not supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
dperl-dls committed Apr 18, 2024
1 parent 350e905 commit 0e89f0a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/ophyd_async/core/async_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ async def _notify_watchers_from(self, iterator: AsyncIterator[WatcherUpdate[T]])
async for update in iterator:
if self._timeout and time.monotonic() > self._timeout:
raise TimeoutError()
self._last_update = replace(
update, time_elapsed=time.monotonic() - self._start
self._last_update = (
update
if update.time_elapsed is None
else replace(update, time_elapsed=time.monotonic() - self._start)
)
for watcher in self._watchers:
self._update_watcher(watcher, self._last_update)
Expand Down
8 changes: 5 additions & 3 deletions tests/core/test_device_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import pytest
from bluesky import plan_stubs as bps
from bluesky.run_engine import RunEngine, TransitionError
from bluesky.run_engine import RunEngine
from super_state_machine.errors import TransitionError

from ophyd_async.core import DEFAULT_TIMEOUT, Device, DeviceCollector, NotConnected
from ophyd_async.epics.motion import motor
Expand All @@ -20,7 +21,8 @@ async def connect(self, sim: bool = True, timeout=DEFAULT_TIMEOUT):
self.connected = True
return await super().connect(sim=True)

async def set(self, new_position: float): ...
async def set(self, new_position: float):
...


async def test_device_collector_handles_top_level_errors(caplog):
Expand Down Expand Up @@ -96,7 +98,7 @@ async def set_up_device():
RE = RunEngine(call_returns_result=True, loop=loop)

def my_plan():
sim_motor.done_moving._backend._set_value(True) # type: ignore
sim_motor.motor_done_move._backend._set_value(True) # type: ignore
yield from bps.mov(sim_motor, 3.14)

RE(my_plan())
Expand Down
18 changes: 12 additions & 6 deletions tests/epics/areadetector/test_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@


class DummyTriggerLogic(TriggerLogic[int]):
def __init__(self): ...
def __init__(self):
...

async def prepare(self, value: int):
return value

async def kickoff(self): ...
async def kickoff(self):
...

async def complete(self): ...
async def complete(self):
...

async def stop(self): ...
async def stop(self):
...


class DummyController(DetectorControl):
def __init__(self) -> None: ...
def __init__(self) -> None:
...

async def arm(
self,
Expand All @@ -49,7 +54,8 @@ async def arm(
) -> AsyncStatus:
return AsyncStatus(asyncio.sleep(0.1))

async def disarm(self): ...
async def disarm(self):
...

def get_deadtime(self, exposure: float) -> float:
return 0.002
Expand Down
4 changes: 2 additions & 2 deletions tests/epics/motion/test_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ async def sim_motor():
AsyncStatus.wrap

async def fake_stop(*args, **kwargs):
sim_motor.done_moving._backend._set_value(True) # type: ignore
sim_motor.motor_done_move._backend._set_value(True) # type: ignore
await asyncio.sleep(0.01)

sim_motor.stop_.trigger = fake_stop # type: ignore
sim_motor.motor_stop.trigger = fake_stop # type: ignore
assert sim_motor.name == "sim_motor"
set_sim_value(sim_motor.motor_egu, "mm")
set_sim_value(sim_motor.precision, 3)
Expand Down

0 comments on commit 0e89f0a

Please sign in to comment.