# Buggy code
async def _press_key(self, key: str, action: InputAction) -> None:
    async def _do_press(keycode: Tuple[int, int], hold: bool):
        await self.protocol.send_and_receive(
            messages.send_hid_event(keycode[0], keycode[1], True)
        )

        if hold:
            # Hardcoded hold time for one second
            await asyncio.sleep(1)

        await self.protocol.send_and_receive(
            messages.send_hid_event(keycode[0], keycode[1], False)
        )

    keycode = _KEY_LOOKUP.get(key)
    if not keycode:
        raise Exception(f"unsupported key: {key}")

    if action == InputAction.SingleTap:
        await _do_press(keycode, False)
    elif action == InputAction.DoubleTap:
        await _do_press(keycode, False)
        await _do_press(keycode, False)
    elif action == InputAction.Hold:
        await _do_press(keycode, True)
    else:
        raise Exception(f"unsupported input action: {action}")


# Traceback (exceptions.TimeoutError)
**pyatv> wake_up
2020-08-13 13:39:01 ERROR: Unknown command: wake_up
pyatv> wakeup
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/scripts/atvremote.py:614: DeprecationWarning: Call to deprecated function wakeup.
value = await tmp(*args)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/scripts/atvremote.py", line 648, in _run_application
return await cli_handler(loop)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/scripts/atvremote.py", line 460, in cli_handler
return await _handle_commands(args, config, loop)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/scripts/atvremote.py", line 558, in _handle_commands
ret = await _handle_device_command(args, cmd, atv, loop)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/scripts/atvremote.py", line 580, in _handle_device_command
return await _exec_command(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/scripts/atvremote.py", line 614, in _exec_command
value = await tmp(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/scripts/atvremote.py", line 228, in cli
await _handle_device_command(self.args, command, self.atv, self.loop)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/scripts/atvremote.py", line 585, in _handle_device_command
return await _exec_command(atv.remote_control, cmd, True, *cmd_args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/scripts/atvremote.py", line 614, in _exec_command
value = await tmp(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/mrp/__init__.py", line 263, in wakeup
await self._press_key("wakeup", InputAction.SingleTap)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/mrp/__init__.py", line 154, in _press_key
await _do_press(keycode, False)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/mrp/__init__.py", line 137, in _do_press
await self.protocol.send_and_receive(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 138, in send_and_receive
return await self._receive(identifier, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 146, in _receive
await asyncio.wait_for(semaphore.acquire(), timeout)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/tasks.py", line 490, in wait_for
raise exceptions.TimeoutError()
asyncio.exceptions.TimeoutError

An error occurred, full stack trace above**

# Fixed code
async def _press_key(self, key: str, action: InputAction) -> None:
    async def _do_press(keycode: Tuple[int, int], hold: bool):
        await self.protocol.send(messages.send_hid_event(keycode[0], keycode[1], True))

        if hold:
            # Hardcoded hold time for one second
            await asyncio.sleep(1)

        await self.protocol.send(messages.send_hid_event(keycode[0], keycode[1], False))

    keycode = _KEY_LOOKUP.get(key)
    if not keycode:
        raise Exception(f"unsupported key: {key}")

    if action == InputAction.SingleTap:
        await _do_press(keycode, False)
    elif action == InputAction.DoubleTap:
        await _do_press(keycode, False)
        await _do_press(keycode, False)
    elif action == InputAction.Hold:
        await _do_press(keycode, True)
    else:
        raise Exception(f"unsupported input action: {action}")