diff --git a/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py b/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py index 30432ae3fdedb19d2e8b19743e63320906b7908e..e9239a834a248af32886df651a5f2463b4764489 100644 --- a/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py +++ b/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py @@ -70,47 +70,32 @@ class attribute_wrapper(attribute): max_dim_y = 0 if access == AttrWriteType.READ_WRITE: - """ if the attribute is of READ_WRITE type, assign the RW and write function to it""" + """ if the attribute is of READ_WRITE type, assign the write function to it""" @only_in_states([DevState.STANDBY, DevState.ON], log=False) @fault_on_error() - def read_RW(device): - # print("read_RW {}, {}x{}, {}, {}".format(me.name, me.dim_x, me.dim_y, me.attr_type, me.value)) + def write_func_wrapper(device, value): """ - read_RW returns the value that was last written to the attribute - """ - try: - return device.value_dict[self] - except Exception as e: - raise Exception(f"Attribute read_RW function error, attempted to read value_dict with key: `{self}`, are you sure this exists?") from e - - @only_in_states([DevState.STANDBY, DevState.ON], log=False) - @fault_on_error() - def write_RW(device, value): - """ - _write_RW writes a value to this attribute + write_func_wrapper writes a value to this attribute """ self.write_function(value) - device.value_dict[self] = value - self.fget = read_RW - self.fset = write_RW + self.fset = write_func_wrapper - else: - """ if the attribute is of READ type, assign the read function to it""" + """ Assign the read function to the attribute""" - @only_in_states([DevState.STANDBY, DevState.ON], log=False) - @fault_on_error() - def read_R(device): - """ - _read_R reads the attribute value, stores it and returns it" - """ - device.value_dict[self] = self.read_function() - return device.value_dict[self] + @only_in_states([DevState.STANDBY, DevState.ON], log=False) + @fault_on_error() + def read_func_wrapper(device): + """ + read_func_wrapper reads the attribute value, stores it and returns it" + """ + device.value_dict[self] = self.read_function() + return device.value_dict[self] - self.fget = read_R + self.fget = read_func_wrapper super().__init__(dtype=datatype, max_dim_y=max_dim_y, max_dim_x=max_dim_x, access=access, **kwargs) diff --git a/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py b/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py index 24ba5f506023f4260a35958cba568936cb2ad76f..651fbabe8a47061811fcfa67f68978ff527cec72 100644 --- a/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py +++ b/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py @@ -308,7 +308,7 @@ class TestAttributeTypes(base.TestCase): if test_type == "scalar": expected = numpy.zeros((1,), dtype=dtype) - val = proxy.scalar_RW + val = proxy.scalar_R elif test_type == "spectrum": expected = numpy.zeros(spectrum_dims, dtype=dtype) val = proxy.spectrum_R diff --git a/tangostationcontrol/tangostationcontrol/test/clients/test_client.py b/tangostationcontrol/tangostationcontrol/test/clients/test_client.py index ea03e850d4021d0d4c40e82a60d4fd1f0a9d67ea..577bab69e469fb26af2252790b22f7f92d2c0ade 100644 --- a/tangostationcontrol/tangostationcontrol/test/clients/test_client.py +++ b/tangostationcontrol/tangostationcontrol/test/clients/test_client.py @@ -73,8 +73,12 @@ class test_client(CommClient): """ takes all gathered data to configure and return the correct read and write functions """ - - self.value = numpy.zeros(dims, dtype) + if dtype == str and dims == (1,): + self.value = '' + elif dims == (1,): + self.value = dtype(0) + else: + self.value = numpy.zeros(dims, dtype) def read_function(): logger.debug("from read_function, reading {} array of type {}".format(dims, dtype))