Attribute enum query in server code?

As part of a Device Server SKA we have a Tango Attribute defined as:

and later in an inherited class in the same server we wish to check the current value of this attribute

Using DeviceProxy this is easy

[quote] admin_labels = list(dp.attribute_query(‘adminMode’).enum_labels)
admin_online = admin_labels.index(‘ON-LINE’)
admin_maintenance = admin_labels.index(‘MAINTENANCE’)
admin_offline = admin_labels.index(‘OFF-LINE’)
admin_not_fitted = admin_labels.index(‘NOT-FITTED’)
current_admin_mode = self.read_adminMode()[/quote]

BUT can we retrieve the ENUM directly from the Attribute itself??? It seems wrong to have to loopback to the server using DeviceProxy!

Ideally it would be good to replace line the

by something like

Hi Brian

I agree the loopback would be a bad approach! You cannot read from the attribute itself, since it doesn’t having a backing variable implicitly. There would be read_adminMode method that will return the current value. In the case of the SKA LMC base classes, the variable returned is self._admin_mode. Unfortunately this variable isn’t actually an enumerated type - that’s something that still needs to be fixed in the SKA Base classes - I guess I should do it soon!

For a more general example, see here:
https://pytango.readthedocs.io/en/stable/data_types.html#devenum-pythonic-usage

That same example shows that on the client side the DeviceProxy will actually give you an IntEnum object directly, so you don’t need to bother with the labels.

Regards,

Anton