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

Fixed use of decorator with arguments

parent 121f067c
No related branches found
No related tags found
No related merge requests found
...@@ -4,20 +4,23 @@ import traceback ...@@ -4,20 +4,23 @@ import traceback
__all__ = ["only_in_states", "only_when_on", "fault_on_error"] __all__ = ["only_in_states", "only_when_on", "fault_on_error"]
def only_in_states(func, allowed_states): def only_in_states(allowed_states):
""" """
Wrapper to call and return the wrapped function if the device is Wrapper to call and return the wrapped function if the device is
in one of the given states. Otherwise None is returned and nothing in one of the given states. Otherwise None is returned and nothing
will be called. will be called.
""" """
@wraps(func) def wrapper(func):
def state_check_wrapper(self, *args, **kwargs): @wraps(func)
if self.get_state() in allowed_states: def state_check_wrapper(self, *args, **kwargs):
return func(self, *args, **kwargs) if self.get_state() in allowed_states:
return func(self, *args, **kwargs)
return None return None
return state_check_wrapper
return state_check_wrapper return wrapper
def only_when_on(func): def only_when_on(func):
""" """
......
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