Skip to content

Manage unsupported sources on Samsung TV #144221

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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