Manage unsupported sources on Samsung TV (#144221)

This commit is contained in:
Simone Chemelli 2025-05-06 13:20:04 +03:00 committed by GitHub
parent 57217b46ed
commit c9a9488ff5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 7 deletions

View File

@ -386,4 +386,8 @@ class SamsungTVDevice(SamsungTVEntity, MediaPlayerEntity):
await self._async_send_keys([SOURCES[source]])
return
LOGGER.error("Unsupported source")
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="source_unsupported",
translation_placeholders={"entity": self.entity_id, "source": source},
)

View File

@ -68,6 +68,9 @@
"service_unsupported": {
"message": "Entity {entity} does not support this action."
},
"source_unsupported": {
"message": "Entity {entity} does not support source {source}."
},
"error_set_volume": {
"message": "Unable to set volume level on {host}: {error}"
},

View File

@ -1105,17 +1105,27 @@ async def test_select_source(hass: HomeAssistant, remote: Mock) -> None:
async def test_select_source_invalid_source(hass: HomeAssistant) -> None:
"""Test for select_source with invalid source."""
source = "INVALID"
with patch("homeassistant.components.samsungtv.bridge.Remote") as remote:
await setup_samsungtv_entry(hass, MOCK_CONFIG)
remote.reset_mock()
with pytest.raises(HomeAssistantError) as exc_info:
await hass.services.async_call(
MP_DOMAIN,
SERVICE_SELECT_SOURCE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_INPUT_SOURCE: "INVALID"},
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_INPUT_SOURCE: source},
True,
)
# control not called
assert remote.control.call_count == 0
assert exc_info.value.translation_domain == DOMAIN
assert exc_info.value.translation_key == "source_unsupported"
assert exc_info.value.translation_placeholders == {
"entity": ENTITY_ID,
"source": source,
}
@pytest.mark.usefixtures("rest_api")