1 """The vizio component."""
3 from __future__
import annotations
7 import voluptuous
as vol
17 from .const
import CONF_APPS, CONF_DEVICE_CLASS, DOMAIN, VIZIO_SCHEMA
18 from .coordinator
import VizioAppsDataUpdateCoordinator
22 """Validate CONF_APPS is only used when CONF_DEVICE_CLASS is MediaPlayerDeviceClass.TV."""
24 config.get(CONF_APPS)
is not None
25 and config[CONF_DEVICE_CLASS] != MediaPlayerDeviceClass.TV
28 f
"'{CONF_APPS}' can only be used if {CONF_DEVICE_CLASS}' is"
29 f
" '{MediaPlayerDeviceClass.TV}'"
35 CONFIG_SCHEMA = vol.Schema(
36 {DOMAIN: vol.All(cv.ensure_list, [vol.All(VIZIO_SCHEMA, validate_apps)])},
37 extra=vol.ALLOW_EXTRA,
40 PLATFORMS = [Platform.MEDIA_PLAYER]
43 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
44 """Component setup, run import config flow for each entry in config."""
46 for entry
in config[DOMAIN]:
47 hass.async_create_task(
48 hass.config_entries.flow.async_init(
49 DOMAIN, context={
"source": SOURCE_IMPORT}, data=entry
57 """Load the saved entities."""
59 hass.data.setdefault(DOMAIN, {})
61 CONF_APPS
not in hass.data[DOMAIN]
62 and entry.data[CONF_DEVICE_CLASS] == MediaPlayerDeviceClass.TV
64 store: Store[list[dict[str, Any]]] =
Store(hass, 1, DOMAIN)
66 await coordinator.async_config_entry_first_refresh()
67 hass.data[DOMAIN][CONF_APPS] = coordinator
69 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
75 """Unload a config entry."""
76 unload_ok = await hass.config_entries.async_unload_platforms(
77 config_entry, PLATFORMS
81 entry.state
is ConfigEntryState.LOADED
82 and entry.entry_id != config_entry.entry_id
83 and entry.data[CONF_DEVICE_CLASS] == MediaPlayerDeviceClass.TV
84 for entry
in hass.config_entries.async_entries(DOMAIN)
86 hass.data[DOMAIN].pop(CONF_APPS,
None)
88 if not hass.data[DOMAIN]:
ConfigType validate_apps(ConfigType config)
bool async_setup(HomeAssistant hass, ConfigType config)
bool async_unload_entry(HomeAssistant hass, ConfigEntry config_entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)