From 34c45eae56ddfdbec70ac4ab647d192ef59386db Mon Sep 17 00:00:00 2001 From: tronikos Date: Fri, 5 Sep 2025 03:29:06 -0700 Subject: [PATCH] Translate exceptions in Android TV Remote media player (#151744) --- .../components/androidtv_remote/media_player.py | 12 ++++++++++-- .../components/androidtv_remote/strings.json | 6 ++++++ .../components/androidtv_remote/test_media_player.py | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/androidtv_remote/media_player.py b/homeassistant/components/androidtv_remote/media_player.py index e4f653cbcf1..371c97cc33e 100644 --- a/homeassistant/components/androidtv_remote/media_player.py +++ b/homeassistant/components/androidtv_remote/media_player.py @@ -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, diff --git a/homeassistant/components/androidtv_remote/strings.json b/homeassistant/components/androidtv_remote/strings.json index b1a220e2a32..0014958717a 100644 --- a/homeassistant/components/androidtv_remote/strings.json +++ b/homeassistant/components/androidtv_remote/strings.json @@ -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}" } } } diff --git a/tests/components/androidtv_remote/test_media_player.py b/tests/components/androidtv_remote/test_media_player.py index 2af8aeb2f56..ba885759979 100644 --- a/tests/components/androidtv_remote/test_media_player.py +++ b/tests/components/androidtv_remote/test_media_player.py @@ -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",