Clear webostv source when the current app is not in the source list (#181381)

This commit is contained in:
darkrain-nl
2026-09-05 21:59:38 +03:00
committed by GitHub
parent 2a1c7d1a86
commit 568f0617fd
3 changed files with 40 additions and 1 deletions
@@ -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
+6 -1
View File
@@ -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,
)
@@ -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)