async def async_step_tv_apps( self, user_input: Dict[str, Any] = None ) -> Dict[str, Any]: """Handle app configuration to complete TV configuration.""" if user_input is not None: if user_input.get(CONF_APPS_TO_INCLUDE_OR_EXCLUDE): # Update stored apps with user entry config keys self._apps[user_input[CONF_INCLUDE_OR_EXCLUDE].lower()] = user_input[ CONF_APPS_TO_INCLUDE_OR_EXCLUDE ].copy() return await self._create_entry_if_unique(self._data) return self.async_show_form( step_id="tv_apps", data_schema=vol.Schema( { vol.Optional( CONF_INCLUDE_OR_EXCLUDE, default=CONF_INCLUDE.title(), ): vol.In([CONF_INCLUDE.title(), CONF_EXCLUDE.title()]), vol.Optional(CONF_APPS_TO_INCLUDE_OR_EXCLUDE): cv.multi_select( VizioAsync.get_apps_list() ), } ), )
def get_apps_list(vizio: VizioAsync, country: str = "all") -> None: apps = vizio.get_apps_list(country) if apps: table = tabulate([{"Name": app} for app in apps], headers="keys") _LOGGER.info("\n%s", table) else: _LOGGER.error("Couldn't get list of apps")
async def async_step_init( self, user_input: Dict[str, Any] = None ) -> Dict[str, Any]: """Manage the vizio options.""" if user_input is not None: if user_input.get(CONF_APPS_TO_INCLUDE_OR_EXCLUDE): user_input[CONF_APPS] = { user_input[CONF_INCLUDE_OR_EXCLUDE]: user_input[ CONF_APPS_TO_INCLUDE_OR_EXCLUDE ].copy() } user_input.pop(CONF_INCLUDE_OR_EXCLUDE) user_input.pop(CONF_APPS_TO_INCLUDE_OR_EXCLUDE) return self.async_create_entry(title="", data=user_input) options = { vol.Optional( CONF_VOLUME_STEP, default=self.config_entry.options.get( CONF_VOLUME_STEP, DEFAULT_VOLUME_STEP ), ): vol.All(vol.Coerce(int), vol.Range(min=1, max=10)) } if self.config_entry.data[CONF_DEVICE_CLASS] == DEVICE_CLASS_TV: default_include_or_exclude = ( CONF_EXCLUDE if self.config_entry.options and CONF_EXCLUDE in self.config_entry.options.get(CONF_APPS) else CONF_EXCLUDE ) options.update( { vol.Optional( CONF_INCLUDE_OR_EXCLUDE, default=default_include_or_exclude.title(), ): vol.All( vol.In([CONF_INCLUDE.title(), CONF_EXCLUDE.title()]), vol.Lower ), vol.Optional( CONF_APPS_TO_INCLUDE_OR_EXCLUDE, default=self.config_entry.options.get(CONF_APPS, {}).get( default_include_or_exclude, [] ), ): cv.multi_select(VizioAsync.get_apps_list()), } ) return self.async_show_form(step_id="init", data_schema=vol.Schema(options))
cv.string, vol.Optional(CONF_ACCESS_TOKEN): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_DEVICE_CLASS, default=DEFAULT_DEVICE_CLASS): vol.All(cv.string, vol.Lower, vol.In([DEVICE_CLASS_TV, DEVICE_CLASS_SPEAKER])), vol.Optional(CONF_VOLUME_STEP, default=DEFAULT_VOLUME_STEP): vol.All(vol.Coerce(int), vol.Range(min=1, max=10)), vol.Optional(CONF_APPS): vol.All( { vol.Exclusive(CONF_INCLUDE, "apps_filter"): vol.All(cv.ensure_list, [vol.All(cv.string, vol.In(VizioAsync.get_apps_list()))]), vol.Exclusive(CONF_EXCLUDE, "apps_filter"): vol.All(cv.ensure_list, [vol.All(cv.string, vol.In(VizioAsync.get_apps_list()))]), vol.Optional(CONF_ADDITIONAL_CONFIGS): vol.All( cv.ensure_list, [ { vol.Required(CONF_NAME): cv.string, vol.Required(CONF_CONFIG): { vol.Required(CONF_APP_ID): cv.string, vol.Required(CONF_NAME_SPACE): vol.Coerce(int), vol.Optional(CONF_MESSAGE, default=None):