From c3a270941fcf7299da8b923d2ca4f1a64764442e Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 17 Aug 2026 15:51:02 -0400 Subject: [PATCH] Fix Vizio media player crash when volume is missing from audio settings (#179431) --- .../components/vizio/media_player.py | 9 +++++--- tests/components/vizio/test_media_player.py | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/vizio/media_player.py b/homeassistant/components/vizio/media_player.py index b9da3c52f673..0ca90b994e0d 100644 --- a/homeassistant/components/vizio/media_player.py +++ b/homeassistant/components/vizio/media_player.py @@ -154,9 +154,12 @@ class VizioDevice(VizioEntity, MediaPlayerEntity): # Audio settings if data.audio_settings: - self._attr_volume_level = ( - float(data.audio_settings[VIZIO_VOLUME].value) / self._max_volume - ) + if VIZIO_VOLUME in data.audio_settings: + self._attr_volume_level = ( + float(data.audio_settings[VIZIO_VOLUME].value) / self._max_volume + ) + else: + self._attr_volume_level = None if VIZIO_MUTE in data.audio_settings: self._attr_is_volume_muted = ( str(data.audio_settings[VIZIO_MUTE].value).lower() == VIZIO_MUTE_ON diff --git a/tests/components/vizio/test_media_player.py b/tests/components/vizio/test_media_player.py index 624db4c4b35c..27684fde14a5 100644 --- a/tests/components/vizio/test_media_player.py +++ b/tests/components/vizio/test_media_player.py @@ -289,6 +289,27 @@ async def _test_service( assert service_call.call_args == call(*args, **kwargs) +@pytest.mark.usefixtures("vizio_connect", "vizio_update") +async def test_tv_without_volume_in_audio_settings( + hass: HomeAssistant, mock_tv_config_entry: MockConfigEntry +) -> None: + """Test a TV whose audio settings omit volume. + + Some firmware does not list `volume` (or `mute`) in the `audio` + settings collection even though the individual settings still work. + The entity must still load, with the unavailable attributes reported + as None instead of raising on every coordinator update. + """ + async with _cm_for_test_setup_without_apps({"eq": CURRENT_EQ}, True): + await setup_integration(hass, mock_tv_config_entry) + + attr = _get_attr_and_assert_base_attr(hass, MediaPlayerDeviceClass.TV, STATE_ON) + # Unset attributes are omitted from the state entirely. + assert attr.get("volume_level") is None + assert attr.get("is_volume_muted") is None + assert attr[ATTR_SOUND_MODE] == CURRENT_EQ + + @pytest.mark.usefixtures("vizio_connect", "vizio_update") async def test_speaker_on( hass: HomeAssistant, mock_speaker_config_entry: MockConfigEntry