async def send_cmd(self, cmd, loop=None):
_LOGGER.info("<STR_LIT>", cmd)<EOL>if cmd not in COMMANDS and cmd not in range(<NUM_LIT:0>, <NUM_LIT>):<EOL><INDENT>_LOGGER.error("<STR_LIT>")<EOL>raise PyMediaroomError("<STR_LIT>")<EOL><DEDENT>keys = []<EOL>if cmd in range(<NUM_LIT:0>, <NUM_LIT>):<EOL><INDENT>for character in str(cmd):<EOL><INDENT>keys.append(COMMANDS["<STR_LIT>"+str(character)])<EOL><DEDENT>if len(keys) < <NUM_LIT:3>:<EOL><INDENT>keys.append(COMMANDS["<STR_LIT:OK>"])<EOL><DEDENT>self.current_channel = cmd<EOL><DEDENT>else:<EOL><INDENT>keys = [COMMANDS[cmd]]<EOL><DEDENT>try:<EOL><INDENT>async with timeout(OPEN_CONTROL_TIMEOUT, loop=loop):<EOL><INDENT>async with self.lock:<EOL><INDENT>_LOGGER.debug("<STR_LIT>", self.stb_ip, REMOTE_CONTROL_PORT)<EOL>stb_recv, stb_send = await asyncio.open_connection(self.stb_ip,<EOL>REMOTE_CONTROL_PORT,<EOL>loop=loop)<EOL>await stb_recv.read(<NUM_LIT:6>)<EOL>_LOGGER.info("<STR_LIT>", self.stb_ip, REMOTE_CONTROL_PORT)<EOL>for key in keys:<EOL><INDENT>_LOGGER.debug("<STR_LIT>", cmd, key)<EOL>stb_send.write("<STR_LIT>".format(key).encode('<STR_LIT>'))<EOL>_ = await stb_recv.read(<NUM_LIT:3>)<EOL>await asyncio.sleep(<NUM_LIT>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except asyncio.TimeoutError as error:<EOL><INDENT>_LOGGER.warning(error)<EOL>raise PyMediaroomError("<STR_LIT>".format(self.stb_ip))<EOL><DEDENT>except ConnectionRefusedError as error:<EOL><INDENT>_LOGGER.warning(error)<EOL>raise PyMediaroomError("<STR_LIT>".format(self.stb_ip))<EOL><DEDENT>
Send remote command to STB.