-
Notifications
You must be signed in to change notification settings - Fork 44
How to work with dev_enum attribute #188
Comments
Hi @cmft, thanks for the report.
That's the expected behavior right? You were expecting I don't have time to work on it at the moment, but feel free to submit a PR! |
Hi @vxgmichel ,
I think so.
O even something more, such as an intEnum e.g. tango_enum.B which What do you think? |
I agree, IntEnum seems to be the best candidate, since it's implicitly converted to int when needed. Then the write value could be converted using:
The following values should then all work: |
TANGO implements DevEnum attributes as an integer value combined with a list label strings. The current PyTango implementation requires the user to fetch the labels separately from the values, and match them up manually. This makes it difficult to use. This new implementation combines the information to create proper enumerated types. #### Client-side changes When the DeviceProxy reads a DevEnum attribute, a Python `enum.IntEnum` object is returned instead of just an integer. This object can be compared to integers directly, so minimal changes are expected for old code. The benefit is that new code using the enumerations directly will be more readable. #### Server-side changes Not much was required here. Added a utility function that extracts the labels from an `enum.Enum` class and verifies that the values will work with the core TANGO implementation. #### Warning The `DeviceProxy` maintains a cache of the attributes, which includes the Enumeration class. If the device server changes the enum_labels for an attribute that the DeviceProxy has already cached, then the DeviceProxy will not know about it. A new instance of the DeviceProxy will have to be created after any significant interface change on the server. Addresses issue tango-controls#188
Implemented in PR #194, will be available in v9.2.4. Thanks for the report! |
TANGO implements DevEnum attributes as an integer value combined with a list label strings. The current PyTango implementation requires the user to fetch the labels separately from the values, and match them up manually. This makes it difficult to use. This new implementation combines the information to create proper enumerated types. #### Client-side changes When the DeviceProxy reads a DevEnum attribute, a Python `enum.IntEnum` object is returned instead of just an integer. This object can be compared to integers directly, so minimal changes are expected for old code. The benefit is that new code using the enumerations directly will be more readable. #### Server-side changes Not much was required here. Added a utility function that extracts the labels from an `enum.Enum` class and verifies that the values will work with the core TANGO implementation. #### Warning The `DeviceProxy` maintains a cache of the attributes, which includes the Enumeration class. If the device server changes the enum_labels for an attribute that the DeviceProxy has already cached, then the DeviceProxy will not know about it. A new instance of the DeviceProxy will have to be created after any significant interface change on the server. Addresses issue tango-controls#188
Dear PyTango experts,
I created a dummy DS with a enum scalar attribute using pogo + manual fixes.
When I use PyTango to read the attribute, I got an
int
value instead anenumeration
. When I read the attribute using jive. It returns the Enumeration string ('B') instead of Enumeration index (1).What I doing wrong? It is something bad defined in the DS .
How should I check the valid values? Assuming consecutive values and comparing with the number of
enum labels
?By the way I could not find DEV_ENUM type documentation in http://pytango.readthedocs.io/en/stable/data_types.html
Thanks in advance,
Carlos
The text was updated successfully, but these errors were encountered: