Suppress vizio logging API call failures to prevent no-op logs (#44388)

This commit is contained in:
Raman Gupta 2021-01-01 06:35:05 -06:00 committed by GitHub
parent 051f6c0e72
commit b651f63ef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 21 deletions

View File

@ -184,10 +184,10 @@ class VizioDevice(MediaPlayerEntity):
async def async_update(self) -> None: async def async_update(self) -> None:
"""Retrieve latest state of the device.""" """Retrieve latest state of the device."""
if not self._model: if not self._model:
self._model = await self._device.get_model_name() self._model = await self._device.get_model_name(log_api_exception=False)
if not self._sw_version: if not self._sw_version:
self._sw_version = await self._device.get_version() self._sw_version = await self._device.get_version(log_api_exception=False)
is_on = await self._device.get_power_state(log_api_exception=False) is_on = await self._device.get_power_state(log_api_exception=False)
@ -236,7 +236,9 @@ class VizioDevice(MediaPlayerEntity):
if not self._available_sound_modes: if not self._available_sound_modes:
self._available_sound_modes = ( self._available_sound_modes = (
await self._device.get_setting_options( await self._device.get_setting_options(
VIZIO_AUDIO_SETTINGS, VIZIO_SOUND_MODE VIZIO_AUDIO_SETTINGS,
VIZIO_SOUND_MODE,
log_api_exception=False,
) )
) )
else: else:
@ -306,6 +308,7 @@ class VizioDevice(MediaPlayerEntity):
setting_type, setting_type,
setting_name, setting_name,
new_value, new_value,
log_api_exception=False,
) )
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
@ -453,52 +456,58 @@ class VizioDevice(MediaPlayerEntity):
"""Select sound mode.""" """Select sound mode."""
if sound_mode in self._available_sound_modes: if sound_mode in self._available_sound_modes:
await self._device.set_setting( await self._device.set_setting(
VIZIO_AUDIO_SETTINGS, VIZIO_SOUND_MODE, sound_mode VIZIO_AUDIO_SETTINGS,
VIZIO_SOUND_MODE,
sound_mode,
log_api_exception=False,
) )
async def async_turn_on(self) -> None: async def async_turn_on(self) -> None:
"""Turn the device on.""" """Turn the device on."""
await self._device.pow_on() await self._device.pow_on(log_api_exception=False)
async def async_turn_off(self) -> None: async def async_turn_off(self) -> None:
"""Turn the device off.""" """Turn the device off."""
await self._device.pow_off() await self._device.pow_off(log_api_exception=False)
async def async_mute_volume(self, mute: bool) -> None: async def async_mute_volume(self, mute: bool) -> None:
"""Mute the volume.""" """Mute the volume."""
if mute: if mute:
await self._device.mute_on() await self._device.mute_on(log_api_exception=False)
self._is_volume_muted = True self._is_volume_muted = True
else: else:
await self._device.mute_off() await self._device.mute_off(log_api_exception=False)
self._is_volume_muted = False self._is_volume_muted = False
async def async_media_previous_track(self) -> None: async def async_media_previous_track(self) -> None:
"""Send previous channel command.""" """Send previous channel command."""
await self._device.ch_down() await self._device.ch_down(log_api_exception=False)
async def async_media_next_track(self) -> None: async def async_media_next_track(self) -> None:
"""Send next channel command.""" """Send next channel command."""
await self._device.ch_up() await self._device.ch_up(log_api_exception=False)
async def async_select_source(self, source: str) -> None: async def async_select_source(self, source: str) -> None:
"""Select input source.""" """Select input source."""
if source in self._available_inputs: if source in self._available_inputs:
await self._device.set_input(source) await self._device.set_input(source, log_api_exception=False)
elif source in self._get_additional_app_names(): elif source in self._get_additional_app_names():
await self._device.launch_app_config( await self._device.launch_app_config(
**next( **next(
app["config"] app["config"]
for app in self._additional_app_configs for app in self._additional_app_configs
if app["name"] == source if app["name"] == source
) ),
log_api_exception=False,
) )
elif source in self._available_apps: elif source in self._available_apps:
await self._device.launch_app(source, self._all_apps) await self._device.launch_app(
source, self._all_apps, log_api_exception=False
)
async def async_volume_up(self) -> None: async def async_volume_up(self) -> None:
"""Increase volume of the device.""" """Increase volume of the device."""
await self._device.vol_up(num=self._volume_step) await self._device.vol_up(num=self._volume_step, log_api_exception=False)
if self._volume_level is not None: if self._volume_level is not None:
self._volume_level = min( self._volume_level = min(
@ -507,7 +516,7 @@ class VizioDevice(MediaPlayerEntity):
async def async_volume_down(self) -> None: async def async_volume_down(self) -> None:
"""Decrease volume of the device.""" """Decrease volume of the device."""
await self._device.vol_down(num=self._volume_step) await self._device.vol_down(num=self._volume_step, log_api_exception=False)
if self._volume_level is not None: if self._volume_level is not None:
self._volume_level = max( self._volume_level = max(
@ -519,10 +528,10 @@ class VizioDevice(MediaPlayerEntity):
if self._volume_level is not None: if self._volume_level is not None:
if volume > self._volume_level: if volume > self._volume_level:
num = int(self._max_volume * (volume - self._volume_level)) num = int(self._max_volume * (volume - self._volume_level))
await self._device.vol_up(num=num) await self._device.vol_up(num=num, log_api_exception=False)
self._volume_level = volume self._volume_level = volume
elif volume < self._volume_level: elif volume < self._volume_level:
num = int(self._max_volume * (self._volume_level - volume)) num = int(self._max_volume * (self._volume_level - volume))
await self._device.vol_down(num=num) await self._device.vol_down(num=num, log_api_exception=False)
self._volume_level = volume self._volume_level = volume

View File

@ -858,6 +858,7 @@ async def test_zeroconf_ignore(
async def test_zeroconf_no_unique_id( async def test_zeroconf_no_unique_id(
hass: HomeAssistantType, hass: HomeAssistantType,
vizio_guess_device_type: pytest.fixture,
vizio_no_unique_id: pytest.fixture, vizio_no_unique_id: pytest.fixture,
) -> None: ) -> None:
"""Test zeroconf discovery aborts when unique_id is None.""" """Test zeroconf discovery aborts when unique_id is None."""

View File

@ -40,6 +40,7 @@ from homeassistant.components.vizio.const import (
CONF_ADDITIONAL_CONFIGS, CONF_ADDITIONAL_CONFIGS,
CONF_APPS, CONF_APPS,
CONF_VOLUME_STEP, CONF_VOLUME_STEP,
DEFAULT_VOLUME_STEP,
DOMAIN, DOMAIN,
SERVICE_UPDATE_SETTING, SERVICE_UPDATE_SETTING,
VIZIO_SCHEMA, VIZIO_SCHEMA,
@ -259,6 +260,7 @@ async def _test_service(
**kwargs, **kwargs,
) -> None: ) -> None:
"""Test generic Vizio media player entity service.""" """Test generic Vizio media player entity service."""
kwargs["log_api_exception"] = False
service_data = {ATTR_ENTITY_ID: ENTITY_ID} service_data = {ATTR_ENTITY_ID: ENTITY_ID}
if additional_service_data: if additional_service_data:
service_data.update(additional_service_data) service_data.update(additional_service_data)
@ -378,13 +380,27 @@ async def test_services(
{ATTR_INPUT_SOURCE: "USB"}, {ATTR_INPUT_SOURCE: "USB"},
"USB", "USB",
) )
await _test_service(hass, MP_DOMAIN, "vol_up", SERVICE_VOLUME_UP, None)
await _test_service(hass, MP_DOMAIN, "vol_down", SERVICE_VOLUME_DOWN, None)
await _test_service( await _test_service(
hass, MP_DOMAIN, "vol_up", SERVICE_VOLUME_SET, {ATTR_MEDIA_VOLUME_LEVEL: 1} hass, MP_DOMAIN, "vol_up", SERVICE_VOLUME_UP, None, num=DEFAULT_VOLUME_STEP
) )
await _test_service( await _test_service(
hass, MP_DOMAIN, "vol_down", SERVICE_VOLUME_SET, {ATTR_MEDIA_VOLUME_LEVEL: 0} hass, MP_DOMAIN, "vol_down", SERVICE_VOLUME_DOWN, None, num=DEFAULT_VOLUME_STEP
)
await _test_service(
hass,
MP_DOMAIN,
"vol_up",
SERVICE_VOLUME_SET,
{ATTR_MEDIA_VOLUME_LEVEL: 1},
num=(100 - 15),
)
await _test_service(
hass,
MP_DOMAIN,
"vol_down",
SERVICE_VOLUME_SET,
{ATTR_MEDIA_VOLUME_LEVEL: 0},
num=(15 - 0),
) )
await _test_service(hass, MP_DOMAIN, "ch_up", SERVICE_MEDIA_NEXT_TRACK, None) await _test_service(hass, MP_DOMAIN, "ch_up", SERVICE_MEDIA_NEXT_TRACK, None)
await _test_service(hass, MP_DOMAIN, "ch_down", SERVICE_MEDIA_PREVIOUS_TRACK, None) await _test_service(hass, MP_DOMAIN, "ch_down", SERVICE_MEDIA_PREVIOUS_TRACK, None)
@ -394,6 +410,9 @@ async def test_services(
"set_setting", "set_setting",
SERVICE_SELECT_SOUND_MODE, SERVICE_SELECT_SOUND_MODE,
{ATTR_SOUND_MODE: "Music"}, {ATTR_SOUND_MODE: "Music"},
"audio",
"eq",
"Music",
) )
# Test that the update_setting service does config validation/transformation correctly # Test that the update_setting service does config validation/transformation correctly
await _test_service( await _test_service(