diff --git a/devices/PCC.py b/devices/PCC.py index e2d3383f398414ea87cf375e6e258125869b3278..d660ff56d7f5dabc327174244369b69fcf082d68 100644 --- a/devices/PCC.py +++ b/devices/PCC.py @@ -160,8 +160,8 @@ class PCC(hardware_device): # -------- @command() @DebugIt() - @only_when_on - @fault_on_error + @only_when_on() + @fault_on_error() def RCU_off(self): """ @@ -171,8 +171,8 @@ class PCC(hardware_device): @command() @DebugIt() - @only_when_on - @fault_on_error + @only_when_on() + @fault_on_error() def RCU_on(self): """ @@ -182,8 +182,8 @@ class PCC(hardware_device): @command() @DebugIt() - @only_when_on - @fault_on_error + @only_when_on() + @fault_on_error() def ADC_on(self): """ @@ -193,8 +193,8 @@ class PCC(hardware_device): @command() @DebugIt() - @only_when_on - @fault_on_error + @only_when_on() + @fault_on_error() def RCU_update(self): """ @@ -204,8 +204,8 @@ class PCC(hardware_device): @command() @DebugIt() - @only_when_on - @fault_on_error + @only_when_on() + @fault_on_error() def CLK_off(self): """ @@ -215,8 +215,8 @@ class PCC(hardware_device): @command() @DebugIt() - @only_when_on - @fault_on_error + @only_when_on() + @fault_on_error() def CLK_on(self): """ @@ -226,8 +226,8 @@ class PCC(hardware_device): @command() @DebugIt() - @only_when_on - @fault_on_error + @only_when_on() + @fault_on_error() def CLK_PLL_setup(self): """ diff --git a/devices/util/attribute_wrapper.py b/devices/util/attribute_wrapper.py index a303cfddbf1ded9044b46b9b8f89807eaaf9e687..9949c9ddec23e794ca2067248296836945840e09 100644 --- a/devices/util/attribute_wrapper.py +++ b/devices/util/attribute_wrapper.py @@ -58,8 +58,8 @@ class attribute_wrapper(attribute): if access == AttrWriteType.READ_WRITE: """ if the attribute is of READ_WRITE type, assign the RW and write function to it""" - @only_when_on - @fault_on_error + @only_when_on() + @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)) """ @@ -71,8 +71,8 @@ class attribute_wrapper(attribute): raise Exception("Attribute read_RW function error, attempted to read value_dict with key: `%s`, are you sure this exists?", self) from e - @only_when_on - @fault_on_error + @only_when_on() + @fault_on_error() def write_RW(device, value): """ _write_RW writes a value to this attribute @@ -87,8 +87,8 @@ class attribute_wrapper(attribute): else: """ if the attribute is of READ type, assign the read function to it""" - @only_when_on - @fault_on_error + @only_when_on() + @fault_on_error() def read_R(device): """ _read_R reads the attribute value, stores it and returns it" diff --git a/devices/util/hardware_device.py b/devices/util/hardware_device.py index ce6a9797daef957261f091a20ce25dea4e7c626c..749ba17ac960c3af1e3d17e01f031aae8d0bc07c 100644 --- a/devices/util/hardware_device.py +++ b/devices/util/hardware_device.py @@ -76,7 +76,7 @@ class hardware_device(Device): @command() @only_in_states([DevState.FAULT, DevState.OFF]) @DebugIt() - @fault_on_error + @fault_on_error() @log_exceptions() def Initialise(self): """ @@ -104,7 +104,7 @@ class hardware_device(Device): @command() @only_in_states([DevState.STANDBY]) @DebugIt() - @fault_on_error + @fault_on_error() @log_exceptions() def On(self): """ diff --git a/devices/util/wrappers.py b/devices/util/wrappers.py index 9dbc45a68dc850b36bd30a0a5b8664d104b58e30..5300ba2a06380599a3457c1624344243b7f5db60 100644 --- a/devices/util/wrappers.py +++ b/devices/util/wrappers.py @@ -22,32 +22,38 @@ def only_in_states(allowed_states): return wrapper -def only_when_on(func): +def only_when_on(): """ Wrapper to call and return the wrapped function if the device is in the ON state. Otherwise None is returned and nothing will be called. """ - @wraps(func) - def when_on_wrapper(self, *args, **kwargs): - if self.get_state() == DevState.ON: - return func(self, *args, **kwargs) + def inner(func): + @wraps(func) + def when_on_wrapper(self, *args, **kwargs): + if self.get_state() == DevState.ON: + return func(self, *args, **kwargs) + + return None - return None + return when_on_wrapper - return when_on_wrapper + return inner -def fault_on_error(func): +def fault_on_error(): """ Wrapper to catch exceptions. Sets the device in a FAULT state if any occurs. """ - @wraps(func) - def error_wrapper(self, *args, **kwargs): - try: - return func(self, *args, **kwargs) - except Exception as e: - self.error_stream("Function failed. Trace: %s", traceback.format_exc()) - self.Fault() - return None + def inner(func): + @wraps(func) + def error_wrapper(self, *args, **kwargs): + try: + return func(self, *args, **kwargs) + except Exception as e: + self.error_stream("Function failed. Trace: %s", traceback.format_exc()) + self.Fault() + return None + + return error_wrapper - return error_wrapper + return inner