Add support for Vizio sound mode (#33200)
* add sound mode support for devices that support it * make setting and unsetting flag better * move eq and audio settings into constants * fix missed statement to use constant instead of hardcoded string * further fixes based on review * bump pyvizio version to include newly identified app
This commit is contained in:
1 parent
f25321e010
commit
081b822d25
8 files changed
+79
-11
No files matched your search
@@ -63,6 +63,9 @@ SUPPORTED_COMMANDS = {
|
||||
),
|
||||
}
|
||||
|
||||
VIZIO_SOUND_MODE = "eq"
|
||||
VIZIO_AUDIO_SETTINGS = "audio"
|
||||
|
||||
# Since Vizio component relies on device class, this dict will ensure that changes to
|
||||
# the values of DEVICE_CLASS_SPEAKER or DEVICE_CLASS_TV don't require changes to pyvizio.
|
||||
VIZIO_DEVICE_CLASSES = {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"domain": "vizio",
|
||||
"name": "VIZIO SmartCast",
|
||||
"documentation": "https://www.home-assistant.io/integrations/vizio",
|
||||
"requirements": ["pyvizio==0.1.44"],
|
||||
"requirements": ["pyvizio==0.1.45"],
|
||||
"dependencies": [],
|
||||
"codeowners": ["@raman325"],
|
||||
"config_flow": true,
|
||||
|
||||
@@ -9,6 +9,7 @@ from pyvizio.const import APP_HOME, APPS, INPUT_APPS, NO_APP_RUNNING, UNKNOWN_AP
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
DEVICE_CLASS_SPEAKER,
|
||||
SUPPORT_SELECT_SOUND_MODE,
|
||||
MediaPlayerDevice,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@@ -41,7 +42,9 @@ from .const import (
|
||||
DOMAIN,
|
||||
ICON,
|
||||
SUPPORTED_COMMANDS,
|
||||
VIZIO_AUDIO_SETTINGS,
|
||||
VIZIO_DEVICE_CLASSES,
|
||||
VIZIO_SOUND_MODE,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -133,6 +136,8 @@ class VizioDevice(MediaPlayerDevice):
|
||||
self._current_input = None
|
||||
self._current_app = None
|
||||
self._current_app_config = None
|
||||
self._current_sound_mode = None
|
||||
self._available_sound_modes = None
|
||||
self._available_inputs = []
|
||||
self._available_apps = []
|
||||
self._conf_apps = config_entry.options.get(CONF_APPS, {})
|
||||
@@ -191,17 +196,29 @@ class VizioDevice(MediaPlayerDevice):
|
||||
self._current_app = None
|
||||
self._current_app_config = None
|
||||
self._available_apps = None
|
||||
self._current_sound_mode = None
|
||||
self._available_sound_modes = None
|
||||
return
|
||||
|
||||
self._state = STATE_ON
|
||||
|
||||
audio_settings = await self._device.get_all_audio_settings(
|
||||
log_api_exception=False
|
||||
audio_settings = await self._device.get_all_settings(
|
||||
VIZIO_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"
|
||||
|
||||
if VIZIO_SOUND_MODE in audio_settings:
|
||||
self._supported_commands |= SUPPORT_SELECT_SOUND_MODE
|
||||
self._current_sound_mode = audio_settings[VIZIO_SOUND_MODE]
|
||||
if self._available_sound_modes is None:
|
||||
self._available_sound_modes = await self._device.get_setting_options(
|
||||
VIZIO_AUDIO_SETTINGS, VIZIO_SOUND_MODE
|
||||
)
|
||||
else:
|
||||
self._supported_commands ^= SUPPORT_SELECT_SOUND_MODE
|
||||
|
||||
input_ = await self._device.get_current_input(log_api_exception=False)
|
||||
if input_ is not None:
|
||||
self._current_input = input_
|
||||
@@ -367,7 +384,7 @@ class VizioDevice(MediaPlayerDevice):
|
||||
return self._config_entry.unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> Dict[str, Any]:
|
||||
"""Return device registry information."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._config_entry.unique_id)},
|
||||
@@ -378,10 +395,27 @@ class VizioDevice(MediaPlayerDevice):
|
||||
}
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
def device_class(self) -> str:
|
||||
"""Return device class for entity."""
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def sound_mode(self) -> Optional[str]:
|
||||
"""Name of the current sound mode."""
|
||||
return self._current_sound_mode
|
||||
|
||||
@property
|
||||
def sound_mode_list(self) -> Optional[List[str]]:
|
||||
"""List of available sound modes."""
|
||||
return self._available_sound_modes
|
||||
|
||||
async def async_select_sound_mode(self, sound_mode):
|
||||
"""Select sound mode."""
|
||||
if sound_mode in self._available_sound_modes:
|
||||
await self._device.set_setting(
|
||||
VIZIO_AUDIO_SETTINGS, VIZIO_SOUND_MODE, sound_mode
|
||||
)
|
||||
|
||||
async def async_turn_on(self) -> None:
|
||||
"""Turn the device on."""
|
||||
await self._device.pow_on()
|
||||
|
||||
Reference in new issue
Block a user