Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only subscribe with event_type="setpoint" when it is available #1034

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ describe future plans.

Release expected by 2024-12-31.

Fixes
-----

- PVPositionerSoftDone used an invalid subscription event type
in unusual cases (with fake ophyd simulated devices).

1.7.1
******

Expand Down
5 changes: 4 additions & 1 deletion apstools/devices/positioner_soft_done.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ def __init__(

self.readback.subscribe(self.cb_readback)
self.setpoint.subscribe(self.cb_setpoint)
self.setpoint.subscribe(self.cb_update_target, event_type="setpoint")
options = {}
if "setpoint" in self.event_types:
options["event_type"] = "setpoint"
self.setpoint.subscribe(self.cb_update_target, **options)

# cancel subscriptions before object is garbage collected
weakref.finalize(self.readback, self.readback.unsubscribe_all)
Expand Down
20 changes: 19 additions & 1 deletion apstools/devices/tests/test_positioner_soft_done.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import math
import time
from contextlib import nullcontext as does_not_raise

import pytest
from ophyd import Component
from ophyd import EpicsSignal
from ophyd.sim import instantiate_fake_device

from ...synApps.swait import UserCalcsDevice
from ...tests import IOC_GP
from ...tests import common_attribute_quantities_test
from ...tests import rand
from ...tests import timed_pause
from ...utils import run_in_thread
from ..positioner_soft_done import TARGET_UNDEFINED
from ..positioner_soft_done import PVPositionerSoftDone
from ..positioner_soft_done import PVPositionerSoftDoneWithStop
from ..positioner_soft_done import TARGET_UNDEFINED

PV_PREFIX = f"{IOC_GP}gp:"
delay_active = False
Expand Down Expand Up @@ -365,3 +367,19 @@ def motion(p, goal):
motion(calcpos, round(rand(-1.1, 0.2), 4)) # known starting position
motion(calcpos, target)
motion(calcpos, target) # issue #725, repeated move to same target


def test_issue_1022():
"""
PVPositionerSoftDone should work with simulated fake devices.

'instantiate_fake_device()' produces a device that does not
have the 'setpoint' event_type.
"""
with does_not_raise():
d = instantiate_fake_device(
PVPositionerSoftDone,
readback_pv="spam:",
setpoint_pv="eggs:",
)
assert d is not None