Skip to content

fix(device_server): add conversion for enum strings from float values#1004

Open
wakonig wants to merge 1 commit into
mainfrom
fix/enum_str_conversion
Open

fix(device_server): add conversion for enum strings from float values#1004
wakonig wants to merge 1 commit into
mainfrom
fix/enum_str_conversion

Conversation

@wakonig

@wakonig wakonig commented Jul 15, 2026

Copy link
Copy Markdown
Member

Description

Converting floats to ints if the underlying signal is based on string enums.

Additional Comments

This currently only happens for legacy scans as they convert the inputs to a numpy array of floats. For v4-type scans the input types are kept. However, using the GUI will likely also emit floats as the inputs are given through a doublespincombobox. So it is probably a good idea to convert them to ints on the device server if possible.

Definition of Done

  • Documentation is up-to-date.

Copilot AI review requested due to automatic review settings July 15, 2026 11:35
@wakonig wakonig self-assigned this Jul 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the device server to coerce float-like enum indices into integers when setting ophyd enum-backed signals, addressing cases where upstream layers (legacy scans / GUI) provide numeric values as floats.

Changes:

  • Add DeviceServer.convert_value_if_needed(...) and apply it in the device server’s _set_device path.
  • Apply the same conversion in the RPC “set/put” path before executing the RPC call.
  • Add unit tests covering conversion behavior (including NumPy float scalars) and error handling for non-integral floats.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
bec_server/bec_server/device_server/device_server.py Adds and applies a helper to convert integral float enum indices to int before calling set.
bec_server/bec_server/device_server/rpc_handler.py Converts the first RPC arg for set/put calls using the new helper before executing the RPC call.
bec_server/tests/tests_device_server/test_device_server.py Adds tests validating enum float conversion (including NumPy floats) and rejection of non-integral floats.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bec_server/bec_server/device_server/device_server.py
Comment thread bec_server/bec_server/device_server/rpc_handler.py Outdated
@wakonig
wakonig force-pushed the fix/enum_str_conversion branch from 1ce8385 to 9b1cc60 Compare July 15, 2026 11:47
@wakonig
wakonig force-pushed the fix/enum_str_conversion branch from 9b1cc60 to 9629021 Compare July 15, 2026 11:49
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
bec_server/bec_server/device_server/rpc_handler.py 0.00% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@wakonig
wakonig requested a review from a team July 15, 2026 12:39
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.

2 participants