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

Merge branch '2021-04-07-cleanup' into 'master'

Generic code cleanup

See merge request !16
parents 734551c7 3612cb18
No related branches found
No related tags found
1 merge request!16Generic code cleanup
File moved
File moved
File moved
......@@ -22,12 +22,13 @@ 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.
"""
def inner(func):
@wraps(func)
def when_on_wrapper(self, *args, **kwargs):
if self.get_state() == DevState.ON:
......@@ -37,10 +38,13 @@ def only_when_on(func):
return when_on_wrapper
def fault_on_error(func):
return inner
def fault_on_error():
"""
Wrapper to catch exceptions. Sets the device in a FAULT state if any occurs.
"""
def inner(func):
@wraps(func)
def error_wrapper(self, *args, **kwargs):
try:
......@@ -51,3 +55,5 @@ def fault_on_error(func):
return None
return error_wrapper
return inner
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment