Skip to content

Commit c9a9488

Browse files
authored
Manage unsupported sources on Samsung TV (#144221)
1 parent 57217b4 commit c9a9488

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

homeassistant/components/samsungtv/media_player.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,8 @@ async def async_select_source(self, source: str) -> None:
386386
await self._async_send_keys([SOURCES[source]])
387387
return
388388

389-
LOGGER.error("Unsupported source")
389+
raise HomeAssistantError(
390+
translation_domain=DOMAIN,
391+
translation_key="source_unsupported",
392+
translation_placeholders={"entity": self.entity_id, "source": source},
393+
)

homeassistant/components/samsungtv/strings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
"service_unsupported": {
6969
"message": "Entity {entity} does not support this action."
7070
},
71+
"source_unsupported": {
72+
"message": "Entity {entity} does not support source {source}."
73+
},
7174
"error_set_volume": {
7275
"message": "Unable to set volume level on {host}: {error}"
7376
},

tests/components/samsungtv/test_media_player.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,17 +1105,27 @@ async def test_select_source(hass: HomeAssistant, remote: Mock) -> None:
11051105

11061106
async def test_select_source_invalid_source(hass: HomeAssistant) -> None:
11071107
"""Test for select_source with invalid source."""
1108+
1109+
source = "INVALID"
1110+
11081111
with patch("homeassistant.components.samsungtv.bridge.Remote") as remote:
11091112
await setup_samsungtv_entry(hass, MOCK_CONFIG)
11101113
remote.reset_mock()
1111-
await hass.services.async_call(
1112-
MP_DOMAIN,
1113-
SERVICE_SELECT_SOURCE,
1114-
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_INPUT_SOURCE: "INVALID"},
1115-
True,
1116-
)
1114+
with pytest.raises(HomeAssistantError) as exc_info:
1115+
await hass.services.async_call(
1116+
MP_DOMAIN,
1117+
SERVICE_SELECT_SOURCE,
1118+
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_INPUT_SOURCE: source},
1119+
True,
1120+
)
11171121
# control not called
11181122
assert remote.control.call_count == 0
1123+
assert exc_info.value.translation_domain == DOMAIN
1124+
assert exc_info.value.translation_key == "source_unsupported"
1125+
assert exc_info.value.translation_placeholders == {
1126+
"entity": ENTITY_ID,
1127+
"source": source,
1128+
}
11191129

11201130

11211131
@pytest.mark.usefixtures("rest_api")

0 commit comments

Comments
 (0)