async def async_play_media(self, media_type, media_id, **kwargs): """Support changing a channel.""" if media_type != MEDIA_TYPE_CHANNEL: _LOGGER.error('Unsupported media type') return # media_id should only be a channel number try: cv.positive_int(media_id) except vol.Invalid: _LOGGER.error('Media ID must be positive integer') return for digit in media_id: await self.hass.async_add_job(self.send_key, 'KEY_' + digit) await asyncio.sleep(KEY_PRESS_TIMEOUT, self.hass.loop)
async def async_play_media(self, media_type, media_id, **kwargs): """Support changing a channel.""" if media_type != MEDIA_TYPE_CHANNEL: LOGGER.error("Unsupported media type") return # media_id should only be a channel number try: cv.positive_int(media_id) except vol.Invalid: LOGGER.error("Media ID must be positive integer") return for digit in media_id: await self.hass.async_add_executor_job(self.send_key, f"KEY_{digit}") await asyncio.sleep(KEY_PRESS_TIMEOUT, self.hass.loop) await self.hass.async_add_executor_job(self.send_key, "KEY_ENTER")
async def async_play_media(self, media_type: str, media_id: str, **kwargs: Any) -> None: """Support changing a channel.""" if media_type == MEDIA_TYPE_APP: await self._async_launch_app(media_id) return if media_type != MEDIA_TYPE_CHANNEL: LOGGER.error("Unsupported media type") return # media_id should only be a channel number try: cv.positive_int(media_id) except vol.Invalid: LOGGER.error("Media ID must be positive integer") return await self._async_send_keys( keys=[f"KEY_{digit}" for digit in media_id] + ["KEY_ENTER"])
async def async_play_media(self, media_type, media_id, **kwargs): """Support changing a channel.""" _LOGGER.debug("function async_play_media") if media_type == MEDIA_TYPE_CHANNEL: # media_id should only be a channel number try: cv.positive_int(media_id) except vol.Invalid: _LOGGER.error("Media ID must be positive integer") return for digit in media_id: await self.hass.async_add_job(self.send_key, "KEY_" + digit) await asyncio.sleep(KEY_PRESS_TIMEOUT, self.hass.loop) await self.hass.async_add_job(self.send_key, "KEY_ENTER") elif media_type == MEDIA_TYPE_KEY: self.send_key(media_id) else: _LOGGER.error("Unsupported media type") return
async def async_play_media(self, media_type, media_id, **kwargs): """Support changing a channel.""" # Type channel if media_type == MEDIA_TYPE_CHANNEL: try: cv.positive_int(media_id.replace("-", "", 1)) # Hyphen must be between numbers if media_id.startswith("-") or media_id.endswith("-"): raise vol.Invalid("") except vol.Invalid: _LOGGER.error( "Media ID must be channel with optional sub-channel, separated by a hyphen (ex. 20-2)" ) return for digit in media_id: await self.hass.async_add_job( self.send_command, "KEY_PLUS100" if digit == "-" else "KEY_" + digit) await self.hass.async_add_job(self.send_command, "KEY_ENTER") # Launch an app elif media_type == MEDIA_TYPE_APP: await self.hass.async_add_job(self.send_command, media_id, "run_app") # Send custom key elif media_type == MEDIA_TYPE_KEY: try: cv.string(media_id) except vol.Invalid: _LOGGER.error('Media ID must be a string (ex: "KEY_HOME"') return await self.hass.async_add_job(self.send_command, media_id) else: _LOGGER.error("Unsupported media type") return
async def async_play_media(self, media_type, media_id, **kwargs): if media_type == MEDIA_TYPE_CHANNEL: try: cv.positive_int(media_id) except vol.Invalid: _LOGGER.error("Media ID must be positive integer") return for digit in media_id: await self._tizenws.send_key("KEY_" + digit, KEYPRESS_DEFAULT_DELAY) await self._tizenws.send_ke("KEY_ENTER") if media_type == MEDIA_TYPE_APP: await self._tizenws.run_app(media_id) elif media_type == MEDIA_TYPE_KEY: try: cv.string(media_id) except vol.Invalid: _LOGGER.error('Media ID must be a string (ex: "KEY_HOME"') return # source_key = media_id await self._tizenws.send_key(media_id) elif media_type == MEDIA_TYPE_URL: try: cv.url(media_id) except vol.Invalid: _LOGGER.error('Media ID must be an url (ex: "http://"') return await self._upnp.async_set_current_media(media_id) elif media_type == "application/vnd.apple.mpegurl": await self._upnp.async_set_current_media(media_id) # elif media_type == MEDIA_TYPE_BROWSER: # self._tizenws.open_browser(media_id) else: _LOGGER.error("Unsupported media type") return self.async_schedule_update_ha_state(True)
async def async_play_media(self, media_type, media_id, **kwargs): """Support changing a channel.""" if media_type == "recording_episode": self.api.play_recording(self.box_id, media_id) elif media_type == MEDIA_TYPE_APP: self.api.select_source(media_id, self.box_id) elif media_type == MEDIA_TYPE_CHANNEL: # media_id should only be a channel number try: cv.positive_int(media_id) except vol.Invalid: _LOGGER.error("Media ID must be positive integer") return if self._box.info.sourceType == "app": self.api._send_key_to_box(self.box_id, "TV") time.sleep(1) for digit in media_id: self.api._send_key_to_box(self.box_id, f"{digit}") else: _LOGGER.error("Unsupported media type")
async def async_play_media(self, media_type, media_id, **kwargs): """Support changing a channel.""" import asyncio import voluptuous as vol import homeassistant.helpers.config_validation as cv if media_type != MEDIA_TYPE_CHANNEL: LOGGER.error("Unsupported media type") return # media_id should only be a channel number try: cv.positive_int(media_id) except vol.Invalid: LOGGER.error("Media ID must be positive integer") return for digit in media_id: await self.hass.async_add_job(self.send_key, "KEY_" + digit) await asyncio.sleep(KEY_PRESS_TIMEOUT, self.hass.loop) await self.hass.async_add_job(self.send_key, "KEY_ENTER")
async def async_play_media(self, media_type, media_id, **kwargs): """Support changing a channel.""" if media_type != MEDIA_TYPE_CHANNEL: _LOGGER.error( self._config.display_name + ' TV: Unsupported media type' ) return # media_id should only be a channel number try: cv.positive_int(media_id) except vol.Invalid: _LOGGER.error( self._config.display_name + ' TV: Media ID must be positive integer' ) return for digit in media_id: await self.hass.async_add_job(self.send_key, 'KEY_' + digit) await asyncio.sleep(KEY_PRESS_TIMEOUT, self.hass.loop)
async def async_play_media(self, media_type: str, media_id: str, **kwargs: Any) -> None: """Support changing a channel.""" if media_type == MEDIA_TYPE_APP: await self._async_send_key(media_id, "run_app") return if media_type != MEDIA_TYPE_CHANNEL: LOGGER.error("Unsupported media type") return # media_id should only be a channel number try: cv.positive_int(media_id) except vol.Invalid: LOGGER.error("Media ID must be positive integer") return for digit in media_id: await self._async_send_key(f"KEY_{digit}") await asyncio.sleep(KEY_PRESS_TIMEOUT) await self._async_send_key("KEY_ENTER")
def indications_validator(indications: Any): if isinstance(indications, Mapping): temp_indications = {**indications} dict_indications = {} for key in indications.keys(): key_str = str(key) match = RE_INDICATIONS_KEY.search(key_str) if match: value = cv.positive_float(indications[key]) idx = cv.positive_int(match.group(3)) if idx in dict_indications and dict_indications[idx] != value: raise vol.Invalid( 'altering indication value for same index: %s' % (idx, ), path=[key_str]) dict_indications[idx] = value del temp_indications[key] if temp_indications: errors = [ vol.Invalid('extra keys not allowed', path=[key]) for key in temp_indications.keys() ] if len(errors) == 1: raise errors[0] raise vol.MultipleInvalid(errors) list_indications = [] for key in sorted(dict_indications.keys()): if len(list_indications) < key - 1: raise vol.Invalid('missing indication index: %d' % (key - 1, )) list_indications.append(dict_indications[key]) else: try: indications = map(str.strip, cv.string(indications).split(',')) except (vol.Invalid, vol.MultipleInvalid): indications = cv.ensure_list(indications) list_indications = list(map(cv.positive_float, indications)) if len(list_indications) < 1: raise vol.Invalid('empty set of indications provided') return list_indications
async def async_play_media(self, media_type, media_id, **kwargs): # Type channel if media_type == MEDIA_TYPE_CHANNEL: """Support changing a channel.""" _LOGGER.debug("Trying to change %s to %s",media_type,media_id) try: cv.positive_int(media_id) except vol.Invalid: _LOGGER.error("Media ID must be positive integer") return if self._api_key and self._device_id: if self._running_app == 'TV/HDMI' and self._cloud_source in ["DigitalTv", "digitalTv", "TV"]: #In TV mode, change channel if self._cloud_channel != media_id: await self.hass.async_add_job(self._smartthings_keys, f"ST_CH{media_id}") else: #Change to TV source before changing channel self.hass.async_add_job(self._smartthings_keys, "ST_TV") time.sleep(5) smartthings.device_update(self) if self._cloud_channel != media_id: await self.hass.async_add_job(self._smartthings_keys, f"ST_CH{media_id}") else: keychain = "" for digit in media_id: keychain += "KEY_{}+".format(digit) keychain += "KEY_ENTER" if self._running_app == 'TV/HDMI': self.hass.async_add_job(self.async_play_media, MEDIA_TYPE_KEY, keychain) else: found_source = False for source in self._source_list: if source.lower() in ["tv", "live tv", "livetv"]: found_source = True await self.hass.async_add_job(self.async_select_source, source) time.sleep(2) break if found_source == False: keychain = "KEY_EXIT+KEY_EXIT+{}".format(keychain) self.hass.async_add_job(self.async_play_media, MEDIA_TYPE_KEY, keychain) # Launch an app elif media_type == MEDIA_TYPE_APP: await self.hass.async_add_job(self.send_command, media_id, "run_app") # Send custom key elif media_type == MEDIA_TYPE_KEY: try: cv.string(media_id) except vol.Invalid: _LOGGER.error('Media ID must be a string (ex: "KEY_HOME"') return source_key = media_id if "+" in source_key: all_source_keys = source_key.split("+") last_was_delay = True for this_key in all_source_keys: if this_key.isdigit(): last_was_delay = True time.sleep(int(this_key)/1000) else: if this_key.startswith("ST_"): await self.hass.async_add_job(self._smartthings_keys, this_key) else: if last_was_delay == False: time.sleep(DEFAULT_KEY_CHAIN_DELAY) last_was_delay = False self.hass.async_add_job(self.send_command, this_key) elif source_key.startswith("ST_"): await self.hass.async_add_job(self._smartthings_keys, source_key) else: await self.hass.async_add_job(self.send_command, source_key) # Play media elif media_type == MEDIA_TYPE_URL: try: cv.url(media_id) except vol.Invalid: _LOGGER.error('Media ID must be an url (ex: "http://"') return await self.hass.async_add_job(self._upnp.set_current_media, media_id) self._playing = True # Trying to make stream component work on TV elif media_type == "application/vnd.apple.mpegurl": await self.hass.async_add_job(self._upnp.set_current_media, media_id) self._playing = True elif media_type == MEDIA_TYPE_BROWSER: try: await self.hass.async_add_job(self._ws.open_browser, media_id) except (ConnectionResetError, AttributeError, BrokenPipeError,websocket._exceptions.WebSocketTimeoutException): self._ws.close() else: _LOGGER.error("Unsupported media type") return
async def async_play_media(self, media_type, media_id, **kwargs): """Support changing a channel.""" # Type channel if media_type == MEDIA_TYPE_CHANNEL: try: cv.positive_int(media_id) except vol.Invalid: _LOGGER.error("Media ID must be positive integer") return for digit in media_id: await self.hass.async_add_job(self.send_command, "KEY_" + digit) await self.hass.async_add_job(self.send_command, "KEY_ENTER") # Launch an app elif media_type == MEDIA_TYPE_APP: await self.hass.async_add_job(self.send_command, media_id, "run_app") # Send custom key elif media_type == MEDIA_TYPE_KEY: try: cv.string(media_id) except vol.Invalid: _LOGGER.error('Media ID must be a string (ex: "KEY_HOME"') return source_key = media_id if "+" in source_key: all_source_keys = source_key.split("+") for this_key in all_source_keys: if this_key.isdigit(): time.sleep(int(this_key) / 1000) else: if this_key.startswith("ST_"): await self.hass.async_add_job( self._smartthings_keys, this_key) else: await self.hass.async_add_job( self.send_command, this_key) elif source_key.startswith("ST_"): await self.hass.async_add_job(self._smartthings_keys, source_key) else: await self.hass.async_add_job(self.send_command, source_key) # Play media elif media_type == MEDIA_TYPE_URL: try: cv.url(media_id) except vol.Invalid: _LOGGER.error('Media ID must be an url (ex: "http://"') return self._upnp.set_current_media(media_id) self._playing = True # Trying to make stream component work on TV elif media_type == "application/vnd.apple.mpegurl": self._upnp.set_current_media(media_id) self._playing = True elif media_type == MEDIA_TYPE_BROWSER: try: self._ws.open_browser(media_id) except (ConnectionResetError, AttributeError, BrokenPipeError, websocket._exceptions.WebSocketTimeoutException): self._ws.close() else: _LOGGER.error("Unsupported media type") return
async def async_play_media(self, media_type, media_id, **kwargs): """Support changing a channel.""" # Type channel if media_type == MEDIA_TYPE_CHANNEL: try: cv.positive_int(media_id) except vol.Invalid: _LOGGER.error("Media ID must be positive integer") return for digit in media_id: await self.hass.async_add_job(self.send_command, "KEY_" + digit) await self.hass.async_add_job(self.send_command, "KEY_ENTER") # Launch an app elif media_type == MEDIA_TYPE_APP: await self.hass.async_add_job(self.send_command, media_id, "run_app") # Send custom key elif media_type == MEDIA_TYPE_KEY: try: cv.string(media_id) except vol.Invalid: _LOGGER.error('Media ID must be a string (ex: "KEY_HOME"') return source_key = media_id if source_key.startswith("ST_"): if source_key.startswith("ST_HDMI"): smartthings.send_command(self, source_key.replace("ST_", ""), "selectsource") elif source_key == "ST_TV": smartthings.send_command(self, "digitalTv", "selectsource") elif "+" in source_key: all_source_keys = source_key.split("+") for this_key in all_source_keys: if this_key.isdigit(): time.sleep(int(this_key) / 1000) else: await self.hass.async_add_job(self.send_command, this_key) else: await self.hass.async_add_job(self.send_command, source_key) # Play media elif media_type == MEDIA_TYPE_URL: try: cv.url(media_id) except vol.Invalid: _LOGGER.error('Media ID must be an url (ex: "http://"') return self._upnp.set_current_media(media_id) self._playing = True # Trying to make stream component work on TV elif media_type == "application/vnd.apple.mpegurl": self._upnp.set_current_media(media_id) self._playing = True else: _LOGGER.error("Unsupported media type") return