def send_key(self, key):
    'Send a key to the tv and handles exceptions.'
    if (self._power_off_in_progress() and (key not in ('KEY_POWER', 'KEY_POWEROFF'))):
        _LOGGER.info('TV is powering off, not sending command: %s', key)
        return
    try:
        retry_count = 1
        for _ in range((retry_count + 1)):
            try:
                self.get_remote().control(key)
                break
            except (self._exceptions_class.ConnectionClosed, BrokenPipeError):
                self._remote = None
        self._state = STATE_ON
    except (self._exceptions_class.UnhandledResponse, self._exceptions_class.AccessDenied):
        self._state = STATE_ON
        self._remote = None
        _LOGGER.debug('Failed sending command %s', key, exc_info=True)
        return
    except OSError:
        self._state = STATE_OFF
        self._remote = None
    if self._power_off_in_progress():
        self._state = STATE_OFF
Send a key to the tv and handles exceptions.
def send_key(self, key):
    
    if (self._power_off_in_progress() and (key not in ('KEY_POWER', 'KEY_POWEROFF'))):
        _LOGGER.info('TV is powering off, not sending command: %s', key)
        return
    try:
        retry_count = 1
        for _ in range((retry_count + 1)):
            try:
                self.get_remote().control(key)
                break
            except (self._exceptions_class.ConnectionClosed, BrokenPipeError):
                self._remote = None
        self._state = STATE_ON
    except (self._exceptions_class.UnhandledResponse, self._exceptions_class.AccessDenied):
        self._state = STATE_ON
        self._remote = None
        _LOGGER.debug('Failed sending command %s', key, exc_info=True)
        return
    except OSError:
        self._state = STATE_OFF
        self._remote = None
    if self._power_off_in_progress():
        self._state = STATE_OFF