diff --git a/homeassistant/components/samsungtv/media_player.py b/homeassistant/components/samsungtv/media_player.py index cc3ca5f142e65..fa4f04a97ec93 100644 --- a/homeassistant/components/samsungtv/media_player.py +++ b/homeassistant/components/samsungtv/media_player.py @@ -386,4 +386,8 @@ async def async_select_source(self, source: str) -> None: 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}, + ) diff --git a/homeassistant/components/samsungtv/strings.json b/homeassistant/components/samsungtv/strings.json index fc3be3fcc1903..17fde5db5bfae 100644 --- a/homeassistant/components/samsungtv/strings.json +++ b/homeassistant/components/samsungtv/strings.json @@ -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}" }, diff --git a/tests/components/samsungtv/test_media_player.py b/tests/components/samsungtv/test_media_player.py index 7dc5c6489d822..d36ff8daeb3b7 100644 --- a/tests/components/samsungtv/test_media_player.py +++ b/tests/components/samsungtv/test_media_player.py @@ -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() - await hass.services.async_call( - MP_DOMAIN, - SERVICE_SELECT_SOURCE, - {ATTR_ENTITY_ID: ENTITY_ID, ATTR_INPUT_SOURCE: "INVALID"}, - True, - ) + 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: 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")