Skip to content

Commit

Permalink
Replaced wait_for_idle in the demo motor with an AsyncStatus wrapped …
Browse files Browse the repository at this point in the history
…call to wait_for_value
  • Loading branch information
burkeds committed Sep 18, 2024
1 parent b9e2ccc commit 6cdaca8
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/ophyd_async/tango/demo/_mover.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from typing import Optional

from bluesky.protocols import Movable, Reading, Stoppable
from bluesky.protocols import Movable, Stoppable

from ophyd_async.core import (
DEFAULT_TIMEOUT,
Expand All @@ -15,6 +15,7 @@
WatchableAsyncStatus,
WatcherUpdate,
observe_value,
wait_for_value,
)
from ophyd_async.tango import TangoReadable, tango_polling
from tango import DevState
Expand Down Expand Up @@ -48,8 +49,9 @@ async def set(self, value: float, timeout: CalculatableTimeout = CalculateTimeou
# For this server, set returns immediately so this status should not be awaited
await self.position.set(value, wait=False, timeout=timeout)

# Wait for the motor to stop
move_status = self.wait_for_idle()
move_status = AsyncStatus(
wait_for_value(self.state, DevState.ON, timeout=timeout)
)

try:
async for current_position in observe_value(
Expand All @@ -67,18 +69,6 @@ async def set(self, value: float, timeout: CalculatableTimeout = CalculateTimeou
if not self._set_success:
raise RuntimeError("Motor was stopped")

@AsyncStatus.wrap
async def wait_for_idle(self):
event = asyncio.Event()

def _wait(value: dict[str, Reading]):
if value[self.state.name]["value"] == DevState.ON:
event.set()

self.state.subscribe(_wait)
await event.wait()
self.state.clear_sub(_wait)

def stop(self, success: bool = True) -> AsyncStatus:
self._set_success = success
return self._stop.trigger()

0 comments on commit 6cdaca8

Please sign in to comment.