Fix Vizio media player crash when volume is missing from audio settings (#179431)

This commit is contained in:
Raman Gupta
2026-08-17 15:51:02 -04:00
committed by GitHub
parent 588d356216
commit c3a270941f
2 changed files with 27 additions and 3 deletions
@@ -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
@@ -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