From 95363d8cece565da61833505e811f390d67f6735 Mon Sep 17 00:00:00 2001 From: Shay Levy <1858925+thecode@users.noreply.github.com> Date: Sun, 22 Nov 2026 22:06:36 +0200 Subject: [PATCH] Hide webOS TV volume controls when the sound output has none (#193711) Co-authored-by: Claude Opus 5.5 --- .../components/webostv/media_player.py | 9 ++++--- tests/components/webostv/test_media_player.py | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index 98d31d919aaf..06bbc7d231ac 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -120,11 +120,14 @@ class LgWebOSMediaPlayerEntity(WebOsTvEntity, RestoreEntity, MediaPlayerEntity): if tv_state.is_on or not self._supported_features: supported = SUPPORT_WEBOSTV + volume_status = tv_state.volume_status if tv_state.sound_output == "external_speaker": supported = supported | SUPPORT_WEBOSTV_VOLUME - elif tv_state.sound_output != "lineout": + # webOS reports volume -1 when the sound output has no volume control + elif ( + tv_state.sound_output != "lineout" and volume_status.get("volume") != -1 + ): supported = supported | SUPPORT_WEBOSTV_VOLUME - volume_status = tv_state.volume_status # The TV speaker always supports volume set, also when combined # with an output that does not. For other outputs webOS 22+ # reports volumeSyncable, webOS 4.x supportvolume, webOS 5/6 @@ -150,7 +153,7 @@ class LgWebOSMediaPlayerEntity(WebOsTvEntity, RestoreEntity, MediaPlayerEntity): self._attr_is_volume_muted = cast(bool, tv_state.muted) self._attr_volume_level = None - if tv_state.volume is not None: + if tv_state.volume is not None and tv_state.volume >= 0: self._attr_volume_level = tv_state.volume / 100.0 self._attr_source = self._current_source diff --git a/tests/components/webostv/test_media_player.py b/tests/components/webostv/test_media_player.py index 80065cac14a7..5c1ded4ffbb6 100644 --- a/tests/components/webostv/test_media_player.py +++ b/tests/components/webostv/test_media_player.py @@ -383,6 +383,13 @@ async def test_entity_attributes( assert attrs.get(ATTR_MEDIA_VOLUME_LEVEL) is None + # Sound output without volume control reports volume -1 + client.tv_state.volume = -1 + await client.mock_state_update() + attrs = hass.states.get(ENTITY_ID).attributes + + assert attrs.get(ATTR_MEDIA_VOLUME_LEVEL) is None + # Channel change client.tv_state.current_channel = CHANNEL_2 await client.mock_state_update() @@ -884,6 +891,18 @@ WEBOS_4_TV_SPEAKER_SUPPORT_VOLUME = { "active": False, "mute": False, } +WEBOS_4_OPTICAL_NO_VOLUME_CONTROL = { + "returnValue": True, + "volumeMax": 100, + "scenario": "mastervolume_ext_speaker_optical", + "muted": False, + "subscribed": True, + "volume": -1, + "action": "requested", + "supportvolume": False, + "slider": False, + "active": False, +} WEBOS_6_ARC_UNKNOWN = { "activeStatus": True, "adjustVolume": True, @@ -943,6 +962,12 @@ SUPPORT_WEBOSTV_VOLUME_SET = ( SUPPORT_WEBOSTV_VOLUME_SET, id="webos_4_support_volume", ), + pytest.param( + "external_optical", + WEBOS_4_OPTICAL_NO_VOLUME_CONTROL, + SUPPORT_WEBOSTV, + id="webos_4_no_volume_control", + ), pytest.param( "external_arc", WEBOS_6_ARC_UNKNOWN,