Skip to content
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
6 changes: 5 additions & 1 deletion homeassistant/components/samsungtv/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
)
3 changes: 3 additions & 0 deletions homeassistant/components/samsungtv/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
},
Expand Down
22 changes: 16 additions & 6 deletions tests/components/samsungtv/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down