mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Use enums in vizio (#61996)
Co-authored-by: Raman Gupta <7243222+raman325@users.noreply.github.com>
This commit is contained in:
parent
2538af4b06
commit
7eed4af6ae
@ -9,7 +9,7 @@ from pyvizio.const import APPS
|
||||
from pyvizio.util import gen_apps_list_from_url
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import DEVICE_CLASS_TV
|
||||
from homeassistant.components.media_player import MediaPlayerDeviceClass
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry, ConfigEntryState
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -24,13 +24,13 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def validate_apps(config: ConfigType) -> ConfigType:
|
||||
"""Validate CONF_APPS is only used when CONF_DEVICE_CLASS == DEVICE_CLASS_TV."""
|
||||
"""Validate CONF_APPS is only used when CONF_DEVICE_CLASS is MediaPlayerDeviceClass.TV."""
|
||||
if (
|
||||
config.get(CONF_APPS) is not None
|
||||
and config[CONF_DEVICE_CLASS] != DEVICE_CLASS_TV
|
||||
and config[CONF_DEVICE_CLASS] != MediaPlayerDeviceClass.TV
|
||||
):
|
||||
raise vol.Invalid(
|
||||
f"'{CONF_APPS}' can only be used if {CONF_DEVICE_CLASS}' is '{DEVICE_CLASS_TV}'"
|
||||
f"'{CONF_APPS}' can only be used if {CONF_DEVICE_CLASS}' is '{MediaPlayerDeviceClass.TV}'"
|
||||
)
|
||||
|
||||
return config
|
||||
@ -63,7 +63,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
if (
|
||||
CONF_APPS not in hass.data[DOMAIN]
|
||||
and entry.data[CONF_DEVICE_CLASS] == DEVICE_CLASS_TV
|
||||
and entry.data[CONF_DEVICE_CLASS] == MediaPlayerDeviceClass.TV
|
||||
):
|
||||
coordinator = VizioAppsDataUpdateCoordinator(hass)
|
||||
await coordinator.async_refresh()
|
||||
@ -83,7 +83,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
||||
if not any(
|
||||
entry.state is ConfigEntryState.LOADED
|
||||
and entry.entry_id != config_entry.entry_id
|
||||
and entry.data[CONF_DEVICE_CLASS] == DEVICE_CLASS_TV
|
||||
and entry.data[CONF_DEVICE_CLASS] == MediaPlayerDeviceClass.TV
|
||||
for entry in hass.config_entries.async_entries(DOMAIN)
|
||||
):
|
||||
hass.data[DOMAIN].pop(CONF_APPS, None)
|
||||
|
@ -12,7 +12,7 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components.media_player import DEVICE_CLASS_SPEAKER, DEVICE_CLASS_TV
|
||||
from homeassistant.components.media_player import MediaPlayerDeviceClass
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_IGNORE,
|
||||
SOURCE_IMPORT,
|
||||
@ -68,7 +68,11 @@ def _get_config_schema(input_dict: dict[str, Any] = None) -> vol.Schema:
|
||||
vol.Required(
|
||||
CONF_DEVICE_CLASS,
|
||||
default=input_dict.get(CONF_DEVICE_CLASS, DEFAULT_DEVICE_CLASS),
|
||||
): vol.All(str, vol.Lower, vol.In([DEVICE_CLASS_TV, DEVICE_CLASS_SPEAKER])),
|
||||
): vol.All(
|
||||
str,
|
||||
vol.Lower,
|
||||
vol.In([MediaPlayerDeviceClass.TV, MediaPlayerDeviceClass.SPEAKER]),
|
||||
),
|
||||
vol.Optional(
|
||||
CONF_ACCESS_TOKEN, default=input_dict.get(CONF_ACCESS_TOKEN, "")
|
||||
): str,
|
||||
@ -134,7 +138,7 @@ class VizioOptionsConfigFlow(config_entries.OptionsFlow):
|
||||
}
|
||||
)
|
||||
|
||||
if self.config_entry.data[CONF_DEVICE_CLASS] == DEVICE_CLASS_TV:
|
||||
if self.config_entry.data[CONF_DEVICE_CLASS] == MediaPlayerDeviceClass.TV:
|
||||
default_include_or_exclude = (
|
||||
CONF_EXCLUDE
|
||||
if self.config_entry.options
|
||||
@ -233,7 +237,9 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self._must_show_form = False
|
||||
elif user_input[
|
||||
CONF_DEVICE_CLASS
|
||||
] == DEVICE_CLASS_SPEAKER or user_input.get(CONF_ACCESS_TOKEN):
|
||||
] == MediaPlayerDeviceClass.SPEAKER or user_input.get(
|
||||
CONF_ACCESS_TOKEN
|
||||
):
|
||||
# Ensure config is valid for a device
|
||||
if not await VizioAsync.validate_ha_config(
|
||||
user_input[CONF_HOST],
|
||||
|
@ -10,9 +10,8 @@ from pyvizio.api.apps import find_app_name
|
||||
from pyvizio.const import APP_HOME, INPUT_APPS, NO_APP_RUNNING, UNKNOWN_APP
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
DEVICE_CLASS_SPEAKER,
|
||||
DEVICE_CLASS_TV,
|
||||
SUPPORT_SELECT_SOUND_MODE,
|
||||
MediaPlayerDeviceClass,
|
||||
MediaPlayerEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@ -252,7 +251,7 @@ class VizioDevice(MediaPlayerEntity):
|
||||
self._available_inputs = [input_.name for input_ in inputs]
|
||||
|
||||
# Return before setting app variables if INPUT_APPS isn't in available inputs
|
||||
if self._attr_device_class == DEVICE_CLASS_SPEAKER or not any(
|
||||
if self._attr_device_class == MediaPlayerDeviceClass.SPEAKER or not any(
|
||||
app for app in INPUT_APPS if app in self._available_inputs
|
||||
):
|
||||
return
|
||||
@ -329,7 +328,7 @@ class VizioDevice(MediaPlayerEntity):
|
||||
self._all_apps = self._apps_coordinator.data
|
||||
self.async_write_ha_state()
|
||||
|
||||
if self._attr_device_class == DEVICE_CLASS_TV:
|
||||
if self._attr_device_class == MediaPlayerDeviceClass.TV:
|
||||
self.async_on_remove(
|
||||
self._apps_coordinator.async_add_listener(apps_list_update)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user