# Path: concert/base.py
# def check(source='*', target='*'):
#     """
#     Decorates a method for checking the device state.
# 
#     *source* denotes the source state that must be present at the time of
#     invoking the decorated method. *target* is the state that the state object
#     will be after successful completion of the method or a list of possible
#     target states.
#     """
#     async def check_now(instance, allowed_states, state_str):
#         state = await instance['state'].get()
#         if state not in allowed_states and '*' not in allowed_states:
#             raise TransitionNotAllowed(f"{state_str} state `{state}' not in `{allowed_states}'")
# 
#     def wrapped(func):
#         sources = [source] if isinstance(source, str) else source
#         targets = [target] if isinstance(target, str) else target
# 
#         @functools.wraps(func)
#         async def call_func(instance, *args, **kwargs):
#             if 'state' not in instance:
#                 raise FSMError('Transitioning requires state parameter')
# 
#             await check_now(instance, sources, 'Current')
#             result = await _execute_func(func, instance, *args, **kwargs)
#             await check_now(instance, targets, 'Final')
# 
#             return result
# 
#         return call_func
# 
#     return wrapped
# 
# class State(Parameter):
# 
#     """
#     Finite state machine.
# 
#     Use this on a class, to keep some sort of known state. In order to enforce
#     restrictions, you would decorate methods on the class with
#     :func:`.check`::
# 
#         class SomeObject(object):
# 
#             state = State(default='standby')
# 
#             @check(source='*', target='moving')
#             def move(self):
#                 pass
# 
#     In case your device doesn't provide information on its state you can use
#     the :func:`.transition` to store the state in an instance of your device::
# 
#         @transition(immediate='moving', target='standby')
#         def _set_some_param(self, param_value):
#             # when the method starts device state is set to *immediate*
#             # long operation goes here
#             pass
#             # the state is set to *target* in the end
# 
#     Accessing the state variable will return the current state value, i.e.::
# 
#         obj = SomeObject()
#         assert obj.state == 'standby'
# 
#     The state cannot be set explicitly by::
# 
#         obj.state = 'some_state'
# 
#     but the object needs to provide methods which transition out of
#     states, the same holds for transitioning out of error states.
#     If the :meth:`_get_state` method is implemented in the device
#     it is always used to get the state, otherwise the state is stored
#     in software.
#     """
# 
#     def __init__(self, default=None, fget=None, fset=None, data=None, check=None, help=None):
#         super(State, self).__init__(fget=fget, help=help)
#         self.default = default
# 
#     def __set__(self, instance, value):
#         raise AttributeError('State cannot be set')
# 
#     def _value(self, instance):
#         if not hasattr(instance, '_state_value'):
#             setattr(instance, '_state_value', self.default)
# 
#         return getattr(instance, '_state_value')
# 
# class AccessorNotImplementedError(NotImplementedError):
# 
#     """Raised when a setter or getter is not implemented."""
# 
# Path: concert/coroutines/base.py
# def background(coroutine):
#     """Same as :func:`.start`, just meant to be used as a decorator."""
#     @functools.wraps(coroutine)
#     def inner(*args, **kwargs):
#         return start(coroutine(*args, **kwargs))
# 
#     return inner
# 
# Path: concert/devices/base.py
# class Device(Parameterizable):
# 
#     """
#     A :class:`.Device` provides locked access to a real-world device.
# 
#     It implements the context protocol to provide locking::
# 
#         async with device:
#             # device is locked
#             await device.set_parameter(1 * q.m)
#             ...
# 
#         # device is unlocked again
#     """
# 
#     def __init__(self):
#         # We have to create the lock early on because it will be accessed in
#         # any add_parameter calls, especially those in the Parameterizable base
#         # class
#         self._lock = asyncio.Lock()
#         super(Device, self).__init__()
# 
#     async def __aenter__(self):
#         await self._lock.acquire()
# 
#         return self
# 
#     async def __aexit__(self, exc_type, exc, tb):
#         self._lock.release()
# 
#     @background
#     async def emergency_stop(self):
#         """Emergency stop."""
#         await self._emergency_stop()
# 
#     async def _emergency_stop(self):
#         """Emergency stop implementation."""
#         pass


from concert.base import check, State, AccessorNotImplementedError
from concert.coroutines.base import background
from concert.devices.base import Device
"""Shutter Device."""


class Shutter(Device):

    """Shutter device class implementation."""

    state = State(default="open")

    def __init__(self):
        super(Shutter, self).__init__()

    @background
    @check(source='closed', target='open')
    async def open(self):
        """open()

        Open the shutter."""
        await self._open()


# Path: concert/base.py
# def check(source='*', target='*'):
#     """
#     Decorates a method for checking the device state.
# 
#     *source* denotes the source state that must be present at the time of
#     invoking the decorated method. *target* is the state that the state object
#     will be after successful completion of the method or a list of possible
#     target states.
#     """
#     async def check_now(instance, allowed_states, state_str):
#         state = await instance['state'].get()
#         if state not in allowed_states and '*' not in allowed_states:
#             raise TransitionNotAllowed(f"{state_str} state `{state}' not in `{allowed_states}'")
# 
#     def wrapped(func):
#         sources = [source] if isinstance(source, str) else source
#         targets = [target] if isinstance(target, str) else target
# 
#         @functools.wraps(func)
#         async def call_func(instance, *args, **kwargs):
#             if 'state' not in instance:
#                 raise FSMError('Transitioning requires state parameter')
# 
#             await check_now(instance, sources, 'Current')
#             result = await _execute_func(func, instance, *args, **kwargs)
#             await check_now(instance, targets, 'Final')
# 
#             return result
# 
#         return call_func
# 
#     return wrapped
# 
# class State(Parameter):
# 
#     """
#     Finite state machine.
# 
#     Use this on a class, to keep some sort of known state. In order to enforce
#     restrictions, you would decorate methods on the class with
#     :func:`.check`::
# 
#         class SomeObject(object):
# 
#             state = State(default='standby')
# 
#             @check(source='*', target='moving')
#             def move(self):
#                 pass
# 
#     In case your device doesn't provide information on its state you can use
#     the :func:`.transition` to store the state in an instance of your device::
# 
#         @transition(immediate='moving', target='standby')
#         def _set_some_param(self, param_value):
#             # when the method starts device state is set to *immediate*
#             # long operation goes here
#             pass
#             # the state is set to *target* in the end
# 
#     Accessing the state variable will return the current state value, i.e.::
# 
#         obj = SomeObject()
#         assert obj.state == 'standby'
# 
#     The state cannot be set explicitly by::
# 
#         obj.state = 'some_state'
# 
#     but the object needs to provide methods which transition out of
#     states, the same holds for transitioning out of error states.
#     If the :meth:`_get_state` method is implemented in the device
#     it is always used to get the state, otherwise the state is stored
#     in software.
#     """
# 
#     def __init__(self, default=None, fget=None, fset=None, data=None, check=None, help=None):
#         super(State, self).__init__(fget=fget, help=help)
#         self.default = default
# 
#     def __set__(self, instance, value):
#         raise AttributeError('State cannot be set')
# 
#     def _value(self, instance):
#         if not hasattr(instance, '_state_value'):
#             setattr(instance, '_state_value', self.default)
# 
#         return getattr(instance, '_state_value')
# 
# class AccessorNotImplementedError(NotImplementedError):
# 
#     """Raised when a setter or getter is not implemented."""
# 
# Path: concert/coroutines/base.py
# def background(coroutine):
#     """Same as :func:`.start`, just meant to be used as a decorator."""
#     @functools.wraps(coroutine)
#     def inner(*args, **kwargs):
#         return start(coroutine(*args, **kwargs))
# 
#     return inner
# 
# Path: concert/devices/base.py
# class Device(Parameterizable):
# 
#     """
#     A :class:`.Device` provides locked access to a real-world device.
# 
#     It implements the context protocol to provide locking::
# 
#         async with device:
#             # device is locked
#             await device.set_parameter(1 * q.m)
#             ...
# 
#         # device is unlocked again
#     """
# 
#     def __init__(self):
#         # We have to create the lock early on because it will be accessed in
#         # any add_parameter calls, especially those in the Parameterizable base
#         # class
#         self._lock = asyncio.Lock()
#         super(Device, self).__init__()
# 
#     async def __aenter__(self):
#         await self._lock.acquire()
# 
#         return self
# 
#     async def __aexit__(self, exc_type, exc, tb):
#         self._lock.release()
# 
#     @background
#     async def emergency_stop(self):
#         """Emergency stop."""
#         await self._emergency_stop()
# 
#     async def _emergency_stop(self):
#         """Emergency stop implementation."""
#         pass


# Path: concert/devices/shutters/base.py
from concert.base import check, State, AccessorNotImplementedError
from concert.coroutines.base import background
from concert.devices.base import Device

"""Shutter Device."""


class Shutter(Device):

    """Shutter device class implementation."""

    state = State(default="open")

    def __init__(self):
        super(Shutter, self).__init__()

    @background
    @check(source='closed', target='open')
    async def open(self):
        """open()

        Open the shutter."""
        await self._open()


    @background