Add exceptions translation to SamsungTV (#142406)

* Add exceptions translation to SmasungTV

* Update strings.json

Co-authored-by: Franck Nijhof <frenck@frenck.nl>

---------

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Simone Chemelli 2025-04-11 11:32:19 +02:00 committed by GitHub
parent a4904a3f2d
commit e1d223f726
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 3 deletions

View File

@ -15,6 +15,7 @@ from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
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,
@ -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},
)

View File

@ -106,5 +106,7 @@ class SamsungTVEntity(CoordinatorEntity[SamsungTVDataUpdateCoordinator], Entity)
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},
)

View File

@ -60,5 +60,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."
}
}
}

View File

@ -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,
}