Skip to content

Add exceptions translation to SamsungTV #142406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion homeassistant/components/samsungtv/device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from homeassistant.helpers.typing import ConfigType

from . import trigger
from .const import DOMAIN
from .helpers import (
async_get_client_by_device_entry,
async_get_device_entry_by_device_id,
Expand Down Expand Up @@ -75,4 +76,8 @@ async def async_attach_trigger(
hass, trigger_config, action, trigger_info
)

raise HomeAssistantError(f"Unhandled trigger type {trigger_type}")
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="unhandled_trigger_type",
translation_placeholders={"trigger_type": trigger_type},
)
4 changes: 3 additions & 1 deletion homeassistant/components/samsungtv/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,7 @@ async def _async_turn_on(self) -> None:
self.entity_id,
)
raise HomeAssistantError(
f"Entity {self.entity_id} does not support this service."
translation_domain=DOMAIN,
translation_key="service_unsupported",
translation_placeholders={"entity": self.entity_id},
)
8 changes: 8 additions & 0 deletions homeassistant/components/samsungtv/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,13 @@
"trigger_type": {
"samsungtv.turn_on": "Device is requested to turn on"
}
},
"exceptions": {
"unhandled_trigger_type": {
"message": "Unhandled trigger type {trigger_type}."
},
"service_unsupported": {
"message": "Entity {entity} does not support this action."
}
}
}
7 changes: 6 additions & 1 deletion tests/components/samsungtv/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ async def test_turn_on_wol(hass: HomeAssistant) -> None:
async def test_turn_on_without_turnon(hass: HomeAssistant, remote: Mock) -> None:
"""Test turn on."""
await setup_samsungtv_entry(hass, MOCK_CONFIG)
with pytest.raises(HomeAssistantError, match="does not support this service"):
with pytest.raises(HomeAssistantError) as exc_info:
await hass.services.async_call(
REMOTE_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_ID}, True
)
# nothing called as not supported feature
assert remote.control.call_count == 0
assert exc_info.value.translation_domain == DOMAIN
assert exc_info.value.translation_key == "service_unsupported"
assert exc_info.value.translation_placeholders == {
"entity": ENTITY_ID,
}