Easier access to DevEnum attributes
TANGO implements DevEnum attributes as an integer value combined with a list label strings. The current PyTango implementation requires the clients 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 no changes are expected for old code, but if required, they should be minimal. 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.
Warnings
- 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. - If a server has enum labels that are not valid Python identifiers it will cause problems.
- Leading spaces will break all attribute access for the
DeviceProxy
. - Other invalid labels can be accessed in the
IntEnum
class via item lookup, e.g.proxy.my_enum['has a bad name!']
will work, whileproxy.my_enum.has a bad name!
obviously won't.
- Leading spaces will break all attribute access for the
Issue: #188 (closed)