Fix TangoDevice getState method

After !1347 (merged), the getState method in TangoDevice is broken. The problem is related to how the DevState enum used in rvalue is handled.

Before the MR:

In [1]: import taurus

In [2]: td = taurus.Device('sys/tg_test/1')

In [3]: td.stateObj
Out[3]: TangoAttribute(tango://localhost:10000/sys/tg_test/1/state)

In [4]: td.stateObj.read()
Out[4]: TangoAttrValue{'rvalue': <DevState.RUNNING: 10>, 'wvalue': None, 'time': TimeVal(tv_nsec = 977, tv_sec = 1760609508, tv_usec = 624664), 'quality': <AttrQuality.ATTR_VALID: 0>, 'error': None, '_attrRef': <weakproxy at 0x74ab143e7380 to TangoAttribute at 0x74aaff5c9090>, '_TangoAttrValue__attrName': 'tango://localhost:10000/sys/tg_test/1/state', '_TangoAttrValue__attrType': 5, 'config': <weakproxy at 0x74ab143e7380 to TangoAttribute at 0x74aaff5c9090>, '_pytango_dev_attr': DeviceAttribute(data_format = tango._tango.AttrDataFormat.SCALAR, dim_x = 1, dim_y = 0, has_failed = False, is_empty = False, name = 'State', nb_read = 1, nb_written = 0, quality = tango._tango.AttrQuality.ATTR_VALID, r_dimension = AttributeDimension(dim_x = 1, dim_y = 0), time = TimeVal(tv_nsec = 977, tv_sec = 1760609508, tv_usec = 624664), type = tango._tango.CmdArgType.DevState, value = tango._tango.DevState.RUNNING, w_dim_x = 0, w_dim_y = 0, w_dimension = AttributeDimension(dim_x = 0, dim_y = 0), w_value = None)}

In [5]: type(td.stateObj.read().rvalue)
Out[5]: <enum 'DevState'>

In [6]: td.stateObj.read().rvalue.value
Out[6]: 10

After:

In [1]: import taurus

In [2]: td = taurus.Device('sys/tg_test/1')

In [3]: td.stateObj.read()
Out[3]: TangoAttrValue{'rvalue': tango._tango.DevState.RUNNING, 'wvalue': None, 'time': TimeVal(tv_nsec = 340, tv_sec = 1760607259, tv_usec = 790186), 'quality': <AttrQuality.ATTR_VALID: 0>, 'error': None, '_attrRef': <weakproxy at 0x7f53c0d0f380 to TangoAttribute at 0x7f5320367e50>, '_TangoAttrValue__attrName': 'tango://localhost:10000/sys/tg_test/1/state', '_TangoAttrValue__attrType': 5, 'config': <weakproxy at 0x7f53c0d0f380 to TangoAttribute at 0x7f5320367e50>, '_pytango_dev_attr': DeviceAttribute(data_format = tango._tango.AttrDataFormat.SCALAR, dim_x = 1, dim_y = 0, has_failed = False, is_empty = False, name = 'State', nb_read = 1, nb_written = 0, quality = tango._tango.AttrQuality.ATTR_VALID, r_dimension = AttributeDimension(dim_x = 1, dim_y = 0), time = TimeVal(tv_nsec = 340, tv_sec = 1760607259, tv_usec = 790186), type = tango._tango.CmdArgType.DevState, value = tango._tango.DevState.RUNNING, w_dim_x = 0, w_dim_y = 0, w_dimension = AttributeDimension(dim_x = 0, dim_y = 0), w_value = None)}

In [4]: type(td.stateObj.read().rvalue)
Out[4]: tango._tango.DevState

In [5]: td.stateObj.read().rvalue.value
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[5], line 1
----> 1 td.stateObj.read().rvalue.value

AttributeError: 'DevState' object has no attribute 'value'

After moving from PyTango to tango namespace, the Python enum wrapper around DevState is no longer used. The returned value is now directly the extencion enum tango._tango.DevState. Both represent the same state but with different types, but we cannot access to the .value (or use strict type checks).

A simple fix in Taurus getState is proposed, but I do not know if it might affect other Taurus components or code that assumes Python enum DevState.

This bug affected Sardana macros and the Sequencer widget (tested in one BL at ALBA), so it is a blocking issue to update.

Merge request reports

Loading