diff --git a/RCUSCC/RCUSCC/wrappers.py b/RCUSCC/RCUSCC/wrappers.py index 14d8f1d6426bee6fd1a0f5b164d30ebd8d07d698..9dbc45a68dc850b36bd30a0a5b8664d104b58e30 100644 --- a/RCUSCC/RCUSCC/wrappers.py +++ b/RCUSCC/RCUSCC/wrappers.py @@ -1,4 +1,4 @@ -from tango import DevState +from tango import DevState, Except from functools import wraps import traceback @@ -7,8 +7,7 @@ __all__ = ["only_in_states", "only_when_on", "fault_on_error"] def only_in_states(allowed_states): """ Wrapper to call and return the wrapped function if the device is - in one of the given states. Otherwise None is returned and nothing - will be called. + in one of the given states. Otherwise a PyTango exception is thrown. """ def wrapper(func): @wraps(func) @@ -16,7 +15,8 @@ def only_in_states(allowed_states): if self.get_state() in allowed_states: return func(self, *args, **kwargs) - return None + self.warn_stream("Illegal command: Function %s can only be called in states %s. Current state: %s" % (func.__name__, allowed_states, self.get_state())) + Except.throw_exception("IllegalCommand", "Function can only be called in states %s. Current state: %s" % (allowed_states, self.get_state()), func.__name__) return state_check_wrapper