Skip to content
Snippets Groups Projects
Commit f8ae9280 authored by Jan David Mol's avatar Jan David Mol
Browse files

Throw exception if function is called in the wrong state, instead of silent failure

parent 1c6947b5
No related branches found
No related tags found
No related merge requests found
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment