home-assistant/core · error · ValueError
Invalid media type: {media_type}
Error message
Invalid media type: {media_type} What it means
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.
Source
Thrown at homeassistant/components/braviatv/coordinator.py:378
await self.client.channel_up()
else:
await self.client.next_track()
@catch_braviatv_errors
async def async_media_previous_track(self) -> None:
"""Send previous track command."""
if self.media_content_type == MediaType.CHANNEL:
await self.client.channel_down()
else:
await self.client.previous_track()
@catch_braviatv_errors
async def async_play_media(
self, media_type: MediaType | str, media_id: str, **kwargs: Any
) -> None:
"""Play a piece of media."""
if media_type not in (MediaType.APP, MediaType.CHANNEL):
raise ValueError(f"Invalid media type: {media_type}")
await self.async_source_find(media_id, media_type)
@catch_braviatv_errors
async def async_select_source(self, source: str) -> None:
"""Set the input source."""
await self.async_source_find(source, SourceType.INPUT)
@catch_braviatv_errors
async def async_send_command(self, command: Iterable[str], repeats: int) -> None:
"""Send command to device."""
for _ in range(repeats):
for cmd in command:
response = await self.client.send_command(cmd)
if not response:
commands = await self.client.get_command_list()
commands_keys = ", ".join(commands.keys())
# Logging an error instead of raising a ValueError
# https://github.com/home-assistant/core/pull/77329#discussion_r955768245View on GitHub (pinned to 58a3fdb3ea)
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.
Example fix
# before
- action: media_player.play_media
target: {entity_id: media_player.sony_tv}
data:
media_content_type: music
media_content_id: http://stream.mp3
# after
- action: media_player.play_media
target: {entity_id: media_player.sony_tv}
data:
media_content_type: app
media_content_id: Netflix Defensive patterns
Strategy: type-guard
Validate before calling
from homeassistant.components.media_player import MediaType
if media_type not in (MediaType.APP, MediaType.CHANNEL):
raise ValueError(f"Bravia supports only app/channel, got {media_type}") Type guard
from homeassistant.components.media_player import MediaType
def is_bravia_media_type(media_type: str) -> bool:
return media_type in (MediaType.APP, MediaType.CHANNEL) Try / catch
try:
await coordinator.async_play_media(media_type, media_id)
except ValueError as err:
if "Invalid media type" in str(err):
# switch to app/channel semantics or route to another player
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Not found {source_type}: {query}
- Media not found: {media_content_type} / {media_content_id}
- username_not_normalized
- Operation mode not supported
- Command not found. Exiting sequence
AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14).
Data as JSON: /api/errors/2cce11bf1e429f44.
Report an issue: GitHub.