Skip to content

Allow setting on hardware backed signals#1078

Merged
DominicOram merged 7 commits intomainfrom
1077_allow_setting_on_hardware_backed_signals
Mar 24, 2025
Merged

Allow setting on hardware backed signals#1078
DominicOram merged 7 commits intomainfrom
1077_allow_setting_on_hardware_backed_signals

Conversation

@DominicOram
Copy link
Contributor

Fixes #1077

Instructions to reviewer on how to test:

  1. Confirm new tests pass

Checks for reviewer

  • Would the PR title make sense to a scientist on a set of release notes
  • If a new device has been added does it follow the standards
  • If changing the API for a pre-existing device, ensure that any beamlines using this device have updated their Bluesky plans accordingly
  • Have the connection tests for the relevant beamline(s) been run via dodal connect ${BEAMLINE}

def __init__(
self,
get_from_hardware_func: Callable[[], Coroutine[Any, Any, SignalDatatypeT]],
set_to_hardware_func: Callable[[], Coroutine[SignalDatatypeT, Any, Any]] = None,
Copy link
Contributor

@Relm-Arrowny Relm-Arrowny Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think set_to_hardware_func should take a set value?

Suggested change
set_to_hardware_func: Callable[[], Coroutine[SignalDatatypeT, Any, Any]] = None,
set_to_hardware_func: Callable[[SignalDatatypeT], Coroutine[SignalDatatypeT, Any, Any]]
| None = None,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I missed it 'cos the linter is still broken due to #1072

@codecov
Copy link

codecov bot commented Feb 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.75%. Comparing base (536807b) to head (511e3a3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1078   +/-   ##
=======================================
  Coverage   97.74%   97.75%           
=======================================
  Files         170      170           
  Lines        6841     6849    +8     
=======================================
+ Hits         6687     6695    +8     
  Misses        154      154           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@Relm-Arrowny Relm-Arrowny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I try to use it, I spotted a couple of things.

Comment on lines +42 to +48
def create_rw_hardware_backed_soft_signal(
datatype: type[SignalDatatypeT],
get_from_hardware_func: Callable[[], Coroutine[Any, Any, SignalDatatypeT]],
set_to_hardware_func: SetHardwareType,
units: str | None = None,
precision: int | None = None,
):
Copy link
Contributor

@Relm-Arrowny Relm-Arrowny Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind, I notice, it will always get overwrite.

Suggested change
def create_rw_hardware_backed_soft_signal(
datatype: type[SignalDatatypeT],
get_from_hardware_func: Callable[[], Coroutine[Any, Any, SignalDatatypeT]],
set_to_hardware_func: SetHardwareType,
units: str | None = None,
precision: int | None = None,
):
def create_rw_hardware_backed_soft_signal(
datatype: type[SignalDatatypeT],
get_from_hardware_func: Callable[[], Coroutine[Any, Any, SignalDatatypeT]],
set_to_hardware_func: Callable[[SignalDatatypeT], Coroutine[Any, Any, None]],
initial_value: SignalDatatypeT | None = None,
units: str | None = None,
precision: int | None = None,
) -> SignalRW:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yh, I think it's an edge case anyway and initial_value is probably never going to be None

)


def create_hardware_backed_soft_signal(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: Make it match soft_r /soft_rw ?

Suggested change
def create_hardware_backed_soft_signal(
def create_r_hardware_backed_soft_signal(

@DominicOram DominicOram requested a review from Relm-Arrowny March 6, 2025 14:44
Copy link
Contributor

@olliesilvester olliesilvester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few minor comments and questions

The device standards page in the docs refer to create_hardware_backed_soft_signal, so we should change that too

Comment on lines +39 to +44
@pytest.mark.parametrize(
"create_hardware_func",
[
create_r_hardware_backed_soft_signal,
do_nothing_on_write_rw_hardware_backed_signal,
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: use pytest request instead of the repeated pytest.mark.parametrize

Co-authored-by: olliesilvester <122091460+olliesilvester@users.noreply.github.com>
@DominicOram
Copy link
Contributor Author

I've addressed some comments but given bluesky/ophyd-async#661 is close to complete and will replace this I don't want to spend too much more time on it.

@DominicOram DominicOram merged commit 63c65a7 into main Mar 24, 2025
19 checks passed
@DominicOram DominicOram deleted the 1077_allow_setting_on_hardware_backed_signals branch March 24, 2025 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow passing a setter to create_hardware_backed_soft_signal

3 participants