From 568f0617fd83b6da19fe3e7941794b9b797ca2ef Mon Sep 17 00:00:00 2001 From: darkrain-nl <24763370+darkrain-nl@users.noreply.github.com> Date: Sat, 5 Sep 2026 20:59:38 +0200 Subject: [PATCH] Clear webostv source when the current app is not in the source list (#181381) --- .../components/webostv/media_player.py | 1 + tests/components/webostv/__init__.py | 7 +++- tests/components/webostv/test_media_player.py | 33 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index a5744cdca76a..bdb48fe70c57 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -202,6 +202,7 @@ class LgWebOSMediaPlayerEntity(WebOsTvEntity, RestoreEntity, MediaPlayerEntity): tv_state = self._client.tv_state source_list = self._source_list self._source_list = {} + self._current_source = None conf_sources = self._sources found_live_tv = False diff --git a/tests/components/webostv/__init__.py b/tests/components/webostv/__init__.py index d9a0a135023d..56bc0b0bfd38 100644 --- a/tests/components/webostv/__init__.py +++ b/tests/components/webostv/__init__.py @@ -1,5 +1,7 @@ """Tests for the LG webOS TV integration.""" +from typing import Any + from homeassistant.components.webostv.const import DOMAIN from homeassistant.const import CONF_CLIENT_SECRET, CONF_HOST from homeassistant.core import HomeAssistant @@ -10,7 +12,9 @@ from tests.common import MockConfigEntry async def setup_webostv( - hass: HomeAssistant, unique_id: str | None = FAKE_UUID + hass: HomeAssistant, + unique_id: str | None = FAKE_UUID, + options: dict[str, Any] | None = None, ) -> MockConfigEntry: """Initialize webostv and media_player for tests.""" entry = MockConfigEntry( @@ -19,6 +23,7 @@ async def setup_webostv( CONF_HOST: HOST, CONF_CLIENT_SECRET: CLIENT_KEY, }, + options=options or {}, title=TV_NAME, unique_id=unique_id, ) diff --git a/tests/components/webostv/test_media_player.py b/tests/components/webostv/test_media_player.py index d4f05c3ea69a..924534211c2d 100644 --- a/tests/components/webostv/test_media_player.py +++ b/tests/components/webostv/test_media_player.py @@ -29,6 +29,7 @@ from homeassistant.components.media_player import ( from homeassistant.components.webostv.const import ( ATTR_PAYLOAD, ATTR_SOUND_OUTPUT, + CONF_SOURCES, DOMAIN, LIVE_TV_APP_ID, WebOsTvCommandError, @@ -538,6 +539,38 @@ async def test_update_sources_live_tv_find(hass: HomeAssistant, client) -> None: assert len(sources) == 1 +async def test_source_unlisted_current_app(hass: HomeAssistant, client) -> None: + """Test source is cleared when the current app is not in the lists.""" + await setup_webostv(hass) + await client.mock_state_update() + + assert hass.states.get(ENTITY_ID).attributes[ATTR_INPUT_SOURCE] == "Live TV" + + # home screen and screen saver are not in the apps or inputs lists + client.tv_state.current_app_id = "com.webos.app.home" + await client.mock_state_update() + + attributes = hass.states.get(ENTITY_ID).attributes + assert ATTR_INPUT_SOURCE not in attributes + assert attributes[ATTR_INPUT_SOURCE_LIST] == ["Input01", "Input02", "Live TV"] + + +async def test_source_cleared_with_filtered_out_sources( + hass: HomeAssistant, client +) -> None: + """Test source is cleared when configured sources match nothing.""" + client.tv_state.inputs = {} + await setup_webostv(hass, options={CONF_SOURCES: ["Netflix"]}) + await client.mock_state_update() + + assert hass.states.get(ENTITY_ID).attributes[ATTR_INPUT_SOURCE] == "Live TV" + + client.tv_state.current_app_id = "com.webos.app.home" + await client.mock_state_update() + + assert ATTR_INPUT_SOURCE not in hass.states.get(ENTITY_ID).attributes + + async def test_app_id(hass: HomeAssistant, client) -> None: """Test app_id follows the foreground app id reported by the TV.""" await setup_webostv(hass)