Open kmadisa opened 6 years ago
There were some recent improvements to enumerated types in PyTango, so this can be done better.
Example of the type of code we want to fix:
def _is_command_allowed(self, command_name):
dp = DeviceProxy(self.get_name())
obstate_labels = list(dp.attribute_query('obsState').enum_labels)
obs_idle = obstate_labels.index('IDLE')
obs_ready = obstate_labels.index('READY')
...
if self.read_obsState() == obs_idle:
...
Attributes are currently instantiated like this:
obsState = attribute(
dtype='DevEnum',
doc="Observing State",
enum_labels=["IDLE", "CONFIGURING", "READY", "SCANNING", "PAUSED", "ABORTED", "FAULT", ],
)
But now that can be done directly from an enumerated type, so rather:
class ObsState(IntEnum):
IDLE = 0
CONFIGURING = 1
READY =2
SCANNING = 3
PAUSED = 4
ABORTED = 5
FAULT = 6
class SKAObsDevice(SKABaseDevice):
obsState = attribute(dtype=ObsState)
...
That allows the initial code to be simply:
def _is_command_allowed(self, command_name):
...
if self.read_obsState() == ObsState.IDLE:
...
However, this is another area we some changes are needed in POGO. The high level code generation should create enumerated types in this new way. There is a short-hand form of creating enumerated types that may be more convenient for POGO:
ObsState = enum.IntEnum('ObsState', ["IDLE", "CONFIGURING", "READY", "SCANNING", "PAUSED", "ABORTED", "FAULT", ], start=0)
Suggested in PR#46: At the moment we instantiate a device proxy and fetch the enum labels every time we check if the command should be allowed to execute. We need to find a way to do this just once and store them for future use while the device is running. (hint: to this in the
always_executed_hook
method).