diff --git a/tangostationcontrol/tangostationcontrol/devices/lofar_device.py b/tangostationcontrol/tangostationcontrol/devices/lofar_device.py index 87a78c05c22928b48da42dd060e8f7e38b24d8f3..49ce86bfb663b87685ee23c205203f1bfce31f26 100644 --- a/tangostationcontrol/tangostationcontrol/devices/lofar_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/lofar_device.py @@ -87,6 +87,15 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas): self.set_state(DevState.OFF) self.set_status("Device is in the OFF state.") + # register a proxy to ourselves, to interact with + # our attributes and commands as a client would. + # + # this is required to get/set attributes. + # + # we cannot write directly to our attribute, as that would not + # trigger a write_{name} call. See https://www.tango-controls.org/community/forum/c/development/c/accessing-own-deviceproxy-class/?page=1#post-2021 + self.proxy = DeviceProxy(self.get_name()) + @log_exceptions() def delete_device(self): """Hook to delete resources allocated in init_device. @@ -231,12 +240,6 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas): 2) Any remaining default properties are set. """ - # we cannot write directly to our attribute, as that would not - # trigger a write_{name} call. See https://www.tango-controls.org/community/forum/c/development/c/accessing-own-deviceproxy-class/?page=1#post-2021 - - # obtain a proxy to myself, to write values - proxy = DeviceProxy(self.get_name()) - # collect all attributes for which defaults are provided attributes_with_defaults = [name for name in dir(self) # collect all attribute members @@ -254,7 +257,7 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas): # set the attribute to the configured default self.debug_stream(f"Setting attribute {name} to {default_value}") - proxy.write_attribute(name, default_value) + self.proxy.write_attribute(name, default_value) except Exception as e: # log which attribute we're addressing raise Exception(f"Cannot assign default to attribute {name}") from e @@ -281,7 +284,7 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas): pollperiod: how often to check the attribute, in seconds. """ - attr = getattr(self, attr_name) + attr = getattr(self.proxy, attr_name) # Poll every half a second for _ in range(math.ceil(timeout/pollperiod)):