mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add is_volume_muted property to vizio integration (#32332)
* add is_muted property and update tests * black * manually set is_muted on async_mute_volume calls to set state early * combine two lines into one * set is_muted to None when device is not on
This commit is contained in:
parent
6a6bf517fe
commit
4f619691df
@ -230,7 +230,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
new_options.update(updated_options)
|
||||
|
||||
self.hass.config_entries.async_update_entry(
|
||||
entry=entry, data=new_data, options=new_options,
|
||||
entry=entry, data=new_data, options=new_options
|
||||
)
|
||||
return self.async_abort(reason="updated_entry")
|
||||
|
||||
|
@ -54,7 +54,7 @@ async def async_setup_entry(
|
||||
|
||||
# If config entry options not set up, set them up, otherwise assign values managed in options
|
||||
volume_step = config_entry.options.get(
|
||||
CONF_VOLUME_STEP, config_entry.data.get(CONF_VOLUME_STEP, DEFAULT_VOLUME_STEP),
|
||||
CONF_VOLUME_STEP, config_entry.data.get(CONF_VOLUME_STEP, DEFAULT_VOLUME_STEP)
|
||||
)
|
||||
|
||||
params = {}
|
||||
@ -107,6 +107,7 @@ class VizioDevice(MediaPlayerDevice):
|
||||
self._state = None
|
||||
self._volume_level = None
|
||||
self._volume_step = volume_step
|
||||
self._is_muted = None
|
||||
self._current_input = None
|
||||
self._available_inputs = None
|
||||
self._device_class = device_class
|
||||
@ -145,15 +146,19 @@ class VizioDevice(MediaPlayerDevice):
|
||||
if not is_on:
|
||||
self._state = STATE_OFF
|
||||
self._volume_level = None
|
||||
self._is_muted = None
|
||||
self._current_input = None
|
||||
self._available_inputs = None
|
||||
return
|
||||
|
||||
self._state = STATE_ON
|
||||
|
||||
volume = await self._device.get_current_volume(log_api_exception=False)
|
||||
if volume is not None:
|
||||
self._volume_level = float(volume) / self._max_volume
|
||||
audio_settings = await self._device.get_all_audio_settings(
|
||||
log_api_exception=False
|
||||
)
|
||||
if audio_settings is not None:
|
||||
self._volume_level = float(audio_settings["volume"]) / self._max_volume
|
||||
self._is_muted = audio_settings["mute"].lower() == "on"
|
||||
|
||||
input_ = await self._device.get_current_input(log_api_exception=False)
|
||||
if input_ is not None:
|
||||
@ -224,6 +229,11 @@ class VizioDevice(MediaPlayerDevice):
|
||||
"""Return the volume level of the device."""
|
||||
return self._volume_level
|
||||
|
||||
@property
|
||||
def is_volume_muted(self):
|
||||
"""Boolean if volume is currently muted."""
|
||||
return self._is_muted
|
||||
|
||||
@property
|
||||
def source(self) -> str:
|
||||
"""Return current input of the device."""
|
||||
@ -272,8 +282,10 @@ class VizioDevice(MediaPlayerDevice):
|
||||
"""Mute the volume."""
|
||||
if mute:
|
||||
await self._device.mute_on()
|
||||
self._is_muted = True
|
||||
else:
|
||||
await self._device.mute_off()
|
||||
self._is_muted = False
|
||||
|
||||
async def async_media_previous_track(self) -> None:
|
||||
"""Send previous channel command."""
|
||||
|
@ -132,8 +132,11 @@ def vizio_update_fixture():
|
||||
"homeassistant.components.vizio.media_player.VizioAsync.can_connect_with_auth_check",
|
||||
return_value=True,
|
||||
), patch(
|
||||
"homeassistant.components.vizio.media_player.VizioAsync.get_current_volume",
|
||||
return_value=int(MAX_VOLUME[DEVICE_CLASS_SPEAKER] / 2),
|
||||
"homeassistant.components.vizio.media_player.VizioAsync.get_all_audio_settings",
|
||||
return_value={
|
||||
"volume": int(MAX_VOLUME[DEVICE_CLASS_SPEAKER] / 2),
|
||||
"mute": "Off",
|
||||
},
|
||||
), patch(
|
||||
"homeassistant.components.vizio.media_player.VizioAsync.get_current_input",
|
||||
return_value=CURRENT_INPUT,
|
||||
|
@ -69,8 +69,8 @@ async def _test_setup(
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.vizio.media_player.VizioAsync.get_current_volume",
|
||||
return_value=int(MAX_VOLUME[vizio_device_class] / 2),
|
||||
"homeassistant.components.vizio.media_player.VizioAsync.get_all_audio_settings",
|
||||
return_value={"volume": int(MAX_VOLUME[vizio_device_class] / 2), "mute": "Off"},
|
||||
), patch(
|
||||
"homeassistant.components.vizio.media_player.VizioAsync.get_power_state",
|
||||
return_value=vizio_power_state,
|
||||
|
Loading…
x
Reference in New Issue
Block a user