-
Notifications
You must be signed in to change notification settings - Fork 4
CA enums with more than 16 values backed by string record #151
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #151 +/- ##
==========================================
+ Coverage 90.63% 90.83% +0.20%
==========================================
Files 41 41
Lines 1943 1954 +11
==========================================
+ Hits 1761 1775 +14
+ Misses 182 179 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting this. I guess this was broken in #102
Looks good. Happy to merge when the coverage is bumped up. Could you add three parameterized tests for cast_from_epics_type, cast_to_epics_type, builder_callable_from_attribute to cover all the branches? |
Aha, so this of course only works when we are using a string enum, which is what I had in my fastcs-eiger branch. I guess we need to decide if we handle several different types of enum based on the underlying type or if we restrict ourselves. We may also want to check that the edit: Seeing from example_p4p_ioc.py that Eva intended the enums to be able to have arbitrary values at least for p4p, so maybe this restriction needs more thought. |
Proposal: something like
Then when we populate the metadata/give choices in the dropdowns we use the labels, which are the string values if all members of the enum have str values, otherwise the names of the members. |
For both p4p and softioc, even if the My suggestion would be that the string values you would put in the case of either an I would suggest in the case of |
Right okay, so the edit: I suppose Enum names can be arbitrary strings if we construct the Enum from a dict, though I don't love it. |
I think it makes sense to have the field name as the descriptive name and the value as the value to send to the device, so that it is consistent between StrEnum and IntEnum. It is annoying that wouldn't allow strings with spaces and via a dict is a bit horrible. Maybe we could add a helper for constructing these? |
test int and string enums in CA, test validation casting to and from epics
I think the clearest thing would be to just use a normal python enum and access it with standard Foo = Enum("Foo", {"One option": 1, "Second option": "2"})
print(Foo["One option"], Foo["One option"].value)
print(Foo["Second option"], Foo["Second option"].value)
Okay, ich bin aus 🫡 |
Tschüss. I think this is okay too, thinking about it, it comes quite naturally to create an Enum class this way especially if we're doing it dynamically, that's how I was intending to do it with fastcs-eiger anyway. It would actually be extra work to exclude this as an option. We can always add a helper function later if we need it for explicit/statically defined Attributes, though I can't think of an interface immediately that would be much better. |
Also, as part of this you might want to add an Without this, you would put |
Yep, that's a good idea. edit: will add test + fix pyright but works with the 'validate' metadata arg. |
This is OK for now, but I am slightly concerned that this mechanism of passing callables and kwargs and boolean flags around to make record instantiation generic and DRY is becoming unreadable. I think this is probably ready to merge once the CI is working? |
Closes #150
May need to add test? Note that I have tested this change against a WIP version of fastcs-eiger running against slightly reworked branch of FastCS #134.
Records with the Enum datatype whose enum_cls have more than 16 members now use
longStringIn
/longStringOut
records instead oflongIn
/longOut
, this allows us to still have labelled dropdowns and string readbacks