{"record":{"id":"2cce11bf1e429f44","repo":"home-assistant/core","slug":"invalid-media-type-media-type","errorCode":null,"errorMessage":"Invalid media type: {media_type}","messagePattern":"Invalid media type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"homeassistant/components/braviatv/coordinator.py","lineNumber":378,"sourceCode":"            await self.client.channel_up()\n        else:\n            await self.client.next_track()\n\n    @catch_braviatv_errors\n    async def async_media_previous_track(self) -> None:\n        \"\"\"Send previous track command.\"\"\"\n        if self.media_content_type == MediaType.CHANNEL:\n            await self.client.channel_down()\n        else:\n            await self.client.previous_track()\n\n    @catch_braviatv_errors\n    async def async_play_media(\n        self, media_type: MediaType | str, media_id: str, **kwargs: Any\n    ) -> None:\n        \"\"\"Play a piece of media.\"\"\"\n        if media_type not in (MediaType.APP, MediaType.CHANNEL):\n            raise ValueError(f\"Invalid media type: {media_type}\")\n        await self.async_source_find(media_id, media_type)\n\n    @catch_braviatv_errors\n    async def async_select_source(self, source: str) -> None:\n        \"\"\"Set the input source.\"\"\"\n        await self.async_source_find(source, SourceType.INPUT)\n\n    @catch_braviatv_errors\n    async def async_send_command(self, command: Iterable[str], repeats: int) -> None:\n        \"\"\"Send command to device.\"\"\"\n        for _ in range(repeats):\n            for cmd in command:\n                response = await self.client.send_command(cmd)\n                if not response:\n                    commands = await self.client.get_command_list()\n                    commands_keys = \", \".join(commands.keys())\n                    # Logging an error instead of raising a ValueError\n                    # https://github.com/home-assistant/core/pull/77329#discussion_r955768245","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/braviatv/coordinator.py#L360-L396","documentation":"ValueError('Invalid media type: {media_type}') raised in async_play_media (coordinator.py:378) when media_type is neither MediaType.APP nor MediaType.CHANNEL. Bravia only supports launching apps and tuning channels via play_media; anything else (music, tvshow, url, playlist...) is rejected before any API call.","triggerScenarios":"Calling media_player.play_media with media_content_type like 'music', 'url', 'video', or an arbitrary string. The check `if media_type not in (MediaType.APP, MediaType.CHANNEL)` fires immediately and the decorated method propagates the raw ValueError.","commonSituations":"Generic cast/play scripts reused from other integrations that assume URL/music playback; YAML with unquoted media_content_type that YAML-parses into a non-string; automations copied from Chromecast/VLC setups.","solutions":["Use media_content_type: app or channel (MediaType.APP / MediaType.CHANNEL).","For apps set media_content_id to the app name; for channels to the channel number.","For actual media files/streams, use a different integration — Bravia TVs cannot play arbitrary media through this API.","Quote the values in YAML so they stay strings."],"exampleFix":"# before\n- action: media_player.play_media\n  target: {entity_id: media_player.sony_tv}\n  data:\n    media_content_type: music\n    media_content_id: http://stream.mp3\n# after\n- action: media_player.play_media\n  target: {entity_id: media_player.sony_tv}\n  data:\n    media_content_type: app\n    media_content_id: Netflix","handlingStrategy":"type-guard","validationCode":"from homeassistant.components.media_player import MediaType\nif media_type not in (MediaType.APP, MediaType.CHANNEL):\n    raise ValueError(f\"Bravia supports only app/channel, got {media_type}\")","typeGuard":"from homeassistant.components.media_player import MediaType\n\ndef is_bravia_media_type(media_type: str) -> bool:\n    return media_type in (MediaType.APP, MediaType.CHANNEL)","tryCatchPattern":"try:\n    await coordinator.async_play_media(media_type, media_id)\nexcept ValueError as err:\n    if \"Invalid media type\" in str(err):\n        # switch to app/channel semantics or route to another player\n        raise","preventionTips":["Restrict play_media UIs (scripts/dashboards) to app and channel types for Bravia entities.","Quote media_content_type values in YAML to avoid type coercion.","Do not reuse Chromecast-style play scripts against Bravia entities."],"tags":["braviatv","home-assistant","invalid-input","play-media","validation"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}