def turn_off(self, **kwargs): try: with HisenseTv(self._host) as tv: tv.send_key_power() except socket.error as e: if "host is unreachable" in str(e).lower(): _LOGGER.debug("unable to reach TV, likely powered off already") else: raise
def media_previous_track(self): """Send previous track command.""" try: with HisenseTv(self._host) as tv: tv.send_key_backs() except socket.error as e: if "host is unreachable" in str(e).lower(): _LOGGER.error( "Unable to reach HisenseTV, likely powered off already") else: _LOGGER.error("Unexpected error: %s", sys.exc_info()[0]) raise
def turn_off(self, **kwargs): try: self._state = STATE_OFF _LOGGER.debug("Sending Power Off to HisenseTV at %s", self._host) with HisenseTv(self._host) as tv: tv.send_key_power() time.sleep(PING_RESPONSE_WAIT_SEC) self.schedule_update_ha_state() except socket.error as e: if "host is unreachable" in str(e).lower(): _LOGGER.error( "Unable to reach HisenseTV, likely powered off already") raise
def set_volume_level(self, volume: float): """Set volume""" try: with HisenseTv(self._host) as tv: volume_int = int(volume * self._max_volume) tv.set_volume(volume_int) _LOGGER.debug("set_volume_level - Volume='%4.3f'", volume) except socket.error as e: if "host is unreachable" in str(e).lower(): _LOGGER.error( "Unable to reach HisenseTV, likely powered off already") else: _LOGGER.error("Unexpected error: %s", sys.exc_info()[0]) raise
def select_source(self, source): """Select input source.""" try: source_int = self._source_map_dict.get(source) _LOGGER.debug("select_source - SourceInt='%s'", source_int) with HisenseTv(self._host) as tv: tv.set_source(source_int, source) self._source = source except socket.error as e: if "host is unreachable" in str(e).lower(): _LOGGER.error( "Unable to reach HisenseTV, likely powered off already") else: _LOGGER.error("Unexpected error: %s", sys.exc_info()[0]) raise
def media_play(self): """Play.""" try: with HisenseTv(self._host) as tv: if self._pause_resume == 'ok': tv.send_key_ok() elif self._pause_resume == 'pause': tv.send_key_pause() else: tv.send_key_play() except socket.error as e: if "host is unreachable" in str(e).lower(): _LOGGER.error( "Unable to reach HisenseTV, likely powered off already") else: _LOGGER.error("Unexpected error: %s", sys.exc_info()[0]) raise
def _refresh_volume(self): """Refresh volume information.""" #_LOGGER.debug("_refresh_volume - starting...") try: with HisenseTv(self._host) as tv: volume_info = tv.get_volume() if volume_info is not None: volume_value = volume_info.get("volume_value") self._volume = (volume_value / self._max_volume) _LOGGER.debug("_refresh_volume - Volume='%s'", volume_value) except socket.error as e: if "host is unreachable" in str(e).lower(): _LOGGER.error( "Unable to reach HisenseTV, likely powered off already") else: _LOGGER.error("Unexpected error: %s", sys.exc_info()[0]) raise
def volume_down(self): """Decrease volume by one.""" try: if self._volume is None: self._volume = 0 else: if ((self._volume * self._max_volume) - 1) <= self._min_volume: self._volume = 0 else: self._volume = self._volume - (1 / self._max_volume) with HisenseTv(self._host) as tv: tv.set_volume(int(self._volume * self._max_volume)) _LOGGER.debug("volume_down - Volume='%.3f'", self._volume) except socket.error as e: if "host is unreachable" in str(e).lower(): _LOGGER.error( "Unable to reach HisenseTV, likely powered off already") else: _LOGGER.error("Unexpected error: %s", sys.exc_info()[0]) raise
def _refresh_sources(self): """Refresh source list""" _LOGGER.debug("_refresh_sources - starting...") try: with HisenseTv(self._host) as tv: source_list = tv.get_sources() if source_list is not None: self._source_list = [] self._source_dict_map = {} for source in source_list: id = source.get("sourceid") # Displayname and sourename appear to always be the same for me #name = source.get("displayname") name = source.get("sourcename") self._source_map_dict[name] = id self._source_list.append(name) #_LOGGER.debug("_refresh_sources - Name='%s'", name) except socket.error as e: if "host is unreachable" in str(e).lower(): _LOGGER.error( "Unable to reach HisenseTV, likely powered off already") else: _LOGGER.error("Unexpected error: %s", sys.exc_info()[0]) raise
def send_command(self, command_value: str): """Send command to TV.""" try: with HisenseTv(self._host) as tv: _LOGGER.debug("send_command - Command='%s'", command_value) if command_value == 'power': if not tv.send_key_power(): _LOGGER.error( "ERROR - send_key - Command 'power' failure.") elif command_value == 'up': if not tv.send_key_up(): _LOGGER.error( "ERROR - send_key - Command 'up' failure.") elif command_value == 'down': if not tv.send_key_down(): _LOGGER.error( "ERROR - send_key - Command 'down' failure.") elif command_value == 'left': if not tv.send_key_left(): _LOGGER.error( "ERROR - send_key - Command 'left' failure.") elif command_value == 'right': if not tv.send_key_right(): _LOGGER.error( "ERROR - send_key - Command 'right' failure.") elif command_value == 'menu': if not tv.send_key_menu(): _LOGGER.error( "ERROR - send_key - Command 'menu' failure.") elif command_value == 'back': if not tv.send_key_back(): _LOGGER.error( "ERROR - send_key - Command 'back' failure.") elif command_value == 'exit': if not tv.send_key_exit(): _LOGGER.error( "ERROR - send_key - Command 'exit' failure.") elif command_value == 'ok': if not tv.send_key_ok(): _LOGGER.error( "ERROR - send_key - Command 'ok' failure.") elif command_value == 'volume_up': if not tv.send_key_volume_up(): _LOGGER.error( "ERROR - send_key - Command 'volume up' failure.") elif command_value == 'volume_down': if not tv.send_key_volume_down(): _LOGGER.error( "ERROR - send_key - Command 'volume down' failure." ) elif command_value == 'forwards': if not tv.send_key_forwards(): _LOGGER.error( "ERROR - send_key - Command 'forwards' failure.") elif command_value == 'backs': if not tv.send_key_backs(): _LOGGER.error( "ERROR - send_key - Command 'backs' failure.") elif command_value == 'stop': if not tv.send_key_stop(): _LOGGER.error( "ERROR - send_key - Command 'stop' failure.") elif command_value == 'play': if not tv.send_key_play(): _LOGGER.error( "ERROR - send_key - Command 'play' failure.") elif command_value == 'pause': if not tv.send_key_pause(): _LOGGER.error( "ERROR - send_key - Command 'pause' failure.") else: _LOGGER.error( "Invalid HisenseTV send_command input parmater: %s", command_value) except socket.error as e: if "host is unreachable" in str(e).lower(): _LOGGER.error( "Unable to reach HisenseTV, likely powered off already") else: _LOGGER.error("Unexpected error: %s", sys.exc_info()[0]) raise