1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Translate exceptions in Android TV Remote media player (#151744)

This commit is contained in:
tronikos
2025-09-05 03:29:06 -07:00
committed by GitHub
parent 71b8da6497
commit 34c45eae56
3 changed files with 18 additions and 4 deletions

View File

@@ -175,7 +175,11 @@ class AndroidTVRemoteMediaPlayerEntity(AndroidTVRemoteBaseEntity, MediaPlayerEnt
"""Play a piece of media."""
if media_type == MediaType.CHANNEL:
if not media_id.isnumeric():
raise ValueError(f"Channel must be numeric: {media_id}")
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="invalid_channel",
translation_placeholders={"media_id": media_id},
)
if self._channel_set_task:
self._channel_set_task.cancel()
self._channel_set_task = asyncio.create_task(
@@ -188,7 +192,11 @@ class AndroidTVRemoteMediaPlayerEntity(AndroidTVRemoteBaseEntity, MediaPlayerEnt
self._send_launch_app_command(media_id)
return
raise ValueError(f"Invalid media type: {media_type}")
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="invalid_media_type",
translation_placeholders={"media_type": media_type},
)
async def async_browse_media(
self,

View File

@@ -85,6 +85,12 @@
"exceptions": {
"connection_closed": {
"message": "Connection to the Android TV device is closed"
},
"invalid_channel": {
"message": "Channel must be numeric: {media_id}"
},
"invalid_media_type": {
"message": "Invalid media type: {media_type}"
}
}
}

View File

@@ -291,7 +291,7 @@ async def test_media_player_play_media(
)
mock_api.send_launch_app_command.assert_called_with("tv.twitch.android.app")
with pytest.raises(ValueError):
with pytest.raises(HomeAssistantError, match="Channel must be numeric: abc"):
await hass.services.async_call(
"media_player",
"play_media",
@@ -303,7 +303,7 @@ async def test_media_player_play_media(
blocking=True,
)
with pytest.raises(ValueError):
with pytest.raises(HomeAssistantError, match="Invalid media type: music"):
await hass.services.async_call(
"media_player",
"play_media",