-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add enum and waveform values #102
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #102 +/- ##
==========================================
- Coverage 88.06% 87.05% -1.01%
==========================================
Files 31 33 +2
Lines 1307 1468 +161
==========================================
+ Hits 1151 1278 +127
- Misses 156 190 +34 ☔ View full report in Codecov by Sentry. |
2fc7114
to
cf9160c
Compare
cf9160c
to
5327339
Compare
047f42b
to
e21f785
Compare
This is needed since not all datatypes are supported on every backend.
e21f785
to
cdaf83a
Compare
Wrong Gar(r)y tagged in the PR description @evalott100 ? |
Hopefully, I'm too on holiday to give a review |
Very mad that you replied Garry!! |
Apologies this is what I get for tying |
Yes we do. The user wants to see the text label and doesn't care if the device gets sent the label or the index. |
This confuses me, the phoebus screen will be updating the IOC values (which would have an mbb record which takes indices or string), which will update the record through What would need to change is where we make the attribute.
This would have the exact same behaviour across the stack so long as we change FastCS/src/fastcs/transport/epics/gui.py Lines 67 to 72 in cdaf83a
so that strings with allowed values also make
|
+1
I did try this at some point in a stale branch and it worked fine so we could keep all this logic inside fastcs-odin, though would be nice if it was resolved higher up. I'm not sure if Odin is unusual in how it handles enums though I suspect there are other potential use cases that would expect ints. (odin-control's ParameterTree doesn't actually properly implemented string labels for enums in its own allowed_values/metadata currently so I was manually adding in these labels for testing, I want to rework that at some point anyway, maybe this should be more of an Odin change) |
I agree. My initial approach was to add a It might clean things up if we added a One solutionUpstream, we could have something like: match datatype:
case Enum(enum_cls):
datatype.add_cast_to(
SOME_EPICS_BACKEND_HASHABLE_IDENTIFIER,
lambda enum: enum.value
)
datatype.add_cast_from(
SOME_EPICS_BACKEND_HASHABLE_IDENTIFIER,
lambda value: enum_cls(value)
) Then FastCS/src/fastcs/transport/epics/ioc.py Lines 247 to 248 in cdaf83a
becomes async def async_write_display(value: T):
record.set(attribute.datatype.cast_to(SOME_EPICS_BACKEND_HASHABLE_IDENTIFIER, value), process=False) and FastCS/src/fastcs/transport/epics/ioc.py Lines 244 to 245 in cdaf83a
becomes
Then downstream you could add_cast_from(
SOME_HTTP_ODIN_BACKEND_HASHABLE_IDENTIFIER,
lambda value: enum_cls(value)
) Since the http client in odin implements it's own updater I'm unsure if it's a good idea though. |
Could we do waveform in a separate PR? I have some comments on that, but I think we could get that in it quickly whereas there is a lot to discuss on enums. |
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.
Initial comments
async def async_write_display(value: T): | ||
record.set(value, process=False) | ||
async def async_write_display(value: T): | ||
record.set(cast_method(value), process=False) |
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.
This should be casting to an EPICS type, but this is using the same method as on_update
.
return datatype.validate(value) | ||
case _: | ||
raise ValueError(f"Unsupported datatype {datatype}") | ||
return cast_from_epics_type |
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.
I am quite confused what these methods are doing. They aren't equivalent to the previous
enum_value_to_index
and enum_index_to_value
functions. Why do they convert between
T
and object
and not T
and int
? Also why do they both just call validate
,
shouldn't one of them be doing the opposite?
I think it was much clearer before when these conditionally defined functions were
inline in ioc.py
and the cast methods were simple.
I won't be adding these to GraphQL in the same PR.
I'd like a quick review before I add tests for the remaining uncovered areas since it'll probably change around. @garryod @marcelldls