# Path: concert/base.py
# def transition(immediate=None, target=None):
#     """Change software state of a device to *immediate*. After the function execution finishes
#     change the state to *target*. On :py:class:`.asyncio.CancelledError`, state is set to *target*
#     and cleanup logic must take place in the callable to be wrapped.
#     """
#     def wrapped(func):
#         @functools.wraps(func)
#         async def call_func(instance, *args, **kwargs):
#             if 'state' not in instance:
#                 raise FSMError('Changing state requires state parameter')
# 
#             # Store the original in case target is None
#             target_state = target if target else await instance['state'].get()
# 
#             if immediate:
#                 setattr(instance, '_state_value', immediate)
# 
#             try:
#                 result = await _execute_func(func, instance, *args, **kwargs)
#                 setattr(instance, '_state_value', target_state)
#             except StateError as error:
#                 setattr(instance, '_state_value', error.state)
#                 raise error
#             except asyncio.CancelledError:
#                 # If *func* is cancelled, *func* must make sure that all cleanup except state update
#                 # happens. If even the state should have some special value, then do not use
#                 # *transition* at all and implement everything in *func*.
#                 setattr(instance, '_state_value', target_state)
#                 raise
# 
#             return result
# 
#         return call_func
# 
#     return wrapped
# 
# Path: concert/devices/io/base.py
# class Signal(Device):
# class IO(Device):
# class IODeviceError(Exception):
#     async def on(self):
#     async def off(self):
#     async def trigger(self, duration=10 * q.ms):
#     async def _on(self):
#     async def _off(self):
#     def __init__(self):
#     def ports(self):
#     def _check(self, port):
#     async def read_port(self, port):
#     async def write_port(self, port, value):
#     async def _read_port(self, port):
#     async def _write_port(self, port, value):


from concert.base import transition
from concert.devices.io import base
"""Dummy IO"""


class IO(base.IO):

    """Dummy I/O device implementation."""

    def __init__(self, port_value=0):
        super(IO, self).__init__()
        self._ports = {0: port_value}

    async def _read_port(self, port):
        return self._ports[port]

    async def _write_port(self, port, value):
        self._ports[port] = value


class Signal(base.Signal):

    """Dummy signal device."""

    @transition(target='on')
    async def _on(self):
        pass


# Path: concert/base.py
# def transition(immediate=None, target=None):
#     """Change software state of a device to *immediate*. After the function execution finishes
#     change the state to *target*. On :py:class:`.asyncio.CancelledError`, state is set to *target*
#     and cleanup logic must take place in the callable to be wrapped.
#     """
#     def wrapped(func):
#         @functools.wraps(func)
#         async def call_func(instance, *args, **kwargs):
#             if 'state' not in instance:
#                 raise FSMError('Changing state requires state parameter')
# 
#             # Store the original in case target is None
#             target_state = target if target else await instance['state'].get()
# 
#             if immediate:
#                 setattr(instance, '_state_value', immediate)
# 
#             try:
#                 result = await _execute_func(func, instance, *args, **kwargs)
#                 setattr(instance, '_state_value', target_state)
#             except StateError as error:
#                 setattr(instance, '_state_value', error.state)
#                 raise error
#             except asyncio.CancelledError:
#                 # If *func* is cancelled, *func* must make sure that all cleanup except state update
#                 # happens. If even the state should have some special value, then do not use
#                 # *transition* at all and implement everything in *func*.
#                 setattr(instance, '_state_value', target_state)
#                 raise
# 
#             return result
# 
#         return call_func
# 
#     return wrapped
# 
# Path: concert/devices/io/base.py
# class Signal(Device):
# class IO(Device):
# class IODeviceError(Exception):
#     async def on(self):
#     async def off(self):
#     async def trigger(self, duration=10 * q.ms):
#     async def _on(self):
#     async def _off(self):
#     def __init__(self):
#     def ports(self):
#     def _check(self, port):
#     async def read_port(self, port):
#     async def write_port(self, port, value):
#     async def _read_port(self, port):
#     async def _write_port(self, port, value):


# Path: concert/devices/io/dummy.py
from concert.base import transition
from concert.devices.io import base

"""Dummy IO"""


class IO(base.IO):

    """Dummy I/O device implementation."""

    def __init__(self, port_value=0):
        super(IO, self).__init__()
        self._ports = {0: port_value}

    async def _read_port(self, port):
        return self._ports[port]

    async def _write_port(self, port, value):
        self._ports[port] = value


class Signal(base.Signal):

    """Dummy signal device."""

    @transition(target='on')
    async def _on(self):
        pass


    @transition(target='off')