Don't attempt to set Vizio is_volume_muted property if Vizio API doesn't provide muted state (#34782)

This commit is contained in:
Raman Gupta 2020-05-01 00:05:45 -04:00 committed by GitHub
parent 793592b2b8
commit 3e06e6b4b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 6 deletions

View file

@ -132,7 +132,7 @@ class VizioDevice(MediaPlayerEntity):
self._state = None
self._volume_level = None
self._volume_step = config_entry.options[CONF_VOLUME_STEP]
self._is_muted = None
self._is_volume_muted = None
self._current_input = None
self._current_app = None
self._current_app_config = None
@ -190,7 +190,7 @@ class VizioDevice(MediaPlayerEntity):
if not is_on:
self._state = STATE_OFF
self._volume_level = None
self._is_muted = None
self._is_volume_muted = None
self._current_input = None
self._available_inputs = None
self._current_app = None
@ -207,7 +207,10 @@ class VizioDevice(MediaPlayerEntity):
)
if audio_settings is not None:
self._volume_level = float(audio_settings["volume"]) / self._max_volume
self._is_muted = audio_settings["mute"].lower() == "on"
if "mute" in audio_settings:
self._is_volume_muted = audio_settings["mute"].lower() == "on"
else:
self._is_volume_muted = None
if VIZIO_SOUND_MODE in audio_settings:
self._supported_commands |= SUPPORT_SELECT_SOUND_MODE
@ -324,7 +327,7 @@ class VizioDevice(MediaPlayerEntity):
@property
def is_volume_muted(self):
"""Boolean if volume is currently muted."""
return self._is_muted
return self._is_volume_muted
@property
def source(self) -> str:
@ -428,10 +431,10 @@ class VizioDevice(MediaPlayerEntity):
"""Mute the volume."""
if mute:
await self._device.mute_on()
self._is_muted = True
self._is_volume_muted = True
else:
await self._device.mute_off()
self._is_muted = False
self._is_volume_muted = False
async def async_media_previous_track(self) -> None:
"""Send previous channel command."""

View file

@ -621,3 +621,26 @@ async def test_setup_with_no_running_app(
assert attr["source"] == "CAST"
assert "app_id" not in attr
assert "app_name" not in attr
async def test_setup_tv_without_mute(
hass: HomeAssistantType,
vizio_connect: pytest.fixture,
vizio_update: pytest.fixture,
) -> None:
"""Test Vizio TV entity setup when mute property isn't returned by Vizio API."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data=vol.Schema(VIZIO_SCHEMA)(MOCK_USER_VALID_TV_CONFIG),
unique_id=UNIQUE_ID,
)
async with _cm_for_test_setup_without_apps(
{"volume": int(MAX_VOLUME[VIZIO_DEVICE_CLASS_TV] / 2)}, STATE_ON,
):
await _add_config_entry_to_hass(hass, config_entry)
attr = _get_attr_and_assert_base_attr(hass, DEVICE_CLASS_TV, STATE_ON)
_assert_sources_and_volume(attr, VIZIO_DEVICE_CLASS_TV)
assert "sound_mode" not in attr
assert "is_volume_muted" not in attr