Add translations for connection closed errors in Android TV Remote (#142523)

This commit is contained in:
tronikos 2025-04-08 01:10:23 -07:00 committed by GitHub
parent 08304ca5f3
commit 167e766811
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 8 deletions

View File

@ -73,7 +73,7 @@ class AndroidTVRemoteBaseEntity(Entity):
self._api.send_key_command(key_code, direction)
except ConnectionClosed as exc:
raise HomeAssistantError(
"Connection to Android TV device is closed"
translation_domain=DOMAIN, translation_key="connection_closed"
) from exc
def _send_launch_app_command(self, app_link: str) -> None:
@ -85,5 +85,5 @@ class AndroidTVRemoteBaseEntity(Entity):
self._api.send_launch_app_command(app_link)
except ConnectionClosed as exc:
raise HomeAssistantError(
"Connection to Android TV device is closed"
translation_domain=DOMAIN, translation_key="connection_closed"
) from exc

View File

@ -21,7 +21,7 @@ from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import AndroidTVRemoteConfigEntry
from .const import CONF_APP_ICON, CONF_APP_NAME
from .const import CONF_APP_ICON, CONF_APP_NAME, DOMAIN
from .entity import AndroidTVRemoteBaseEntity
PARALLEL_UPDATES = 0
@ -233,5 +233,5 @@ class AndroidTVRemoteMediaPlayerEntity(AndroidTVRemoteBaseEntity, MediaPlayerEnt
await asyncio.sleep(delay_secs)
except ConnectionClosed as exc:
raise HomeAssistantError(
"Connection to Android TV device is closed"
translation_domain=DOMAIN, translation_key="connection_closed"
) from exc

View File

@ -54,5 +54,10 @@
}
}
}
},
"exceptions": {
"connection_closed": {
"message": "Connection to the Android TV device is closed"
}
}
}

View File

@ -391,7 +391,9 @@ async def test_media_player_connection_closed(
assert mock_config_entry.state is ConfigEntryState.LOADED
mock_api.send_key_command.side_effect = ConnectionClosed()
with pytest.raises(HomeAssistantError):
with pytest.raises(
HomeAssistantError, match="Connection to the Android TV device is closed"
):
await hass.services.async_call(
"media_player",
"media_pause",
@ -400,7 +402,9 @@ async def test_media_player_connection_closed(
)
mock_api.send_launch_app_command.side_effect = ConnectionClosed()
with pytest.raises(HomeAssistantError):
with pytest.raises(
HomeAssistantError, match="Connection to the Android TV device is closed"
):
await hass.services.async_call(
"media_player",
"play_media",

View File

@ -183,7 +183,9 @@ async def test_remote_connection_closed(
assert mock_config_entry.state is ConfigEntryState.LOADED
mock_api.send_key_command.side_effect = ConnectionClosed()
with pytest.raises(HomeAssistantError):
with pytest.raises(
HomeAssistantError, match="Connection to the Android TV device is closed"
):
await hass.services.async_call(
"remote",
"send_command",
@ -197,7 +199,9 @@ async def test_remote_connection_closed(
assert mock_api.send_key_command.mock_calls == [call("DPAD_LEFT", "SHORT")]
mock_api.send_launch_app_command.side_effect = ConnectionClosed()
with pytest.raises(HomeAssistantError):
with pytest.raises(
HomeAssistantError, match="Connection to the Android TV device is closed"
):
await hass.services.async_call(
"remote",
"turn_on",