Esempio n. 1
0
    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()
                    ),
                }
            ),
        )
Esempio n. 2
0
    async def async_step_init(self, user_input: dict[str, Any] = None) -> FlowResult:
        """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.Schema(
            {
                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_INCLUDE
            )
            options = options.extend(
                {
                    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(
                        [
                            APP_HOME["name"],
                            *(
                                app["name"]
                                for app in self.hass.data[DOMAIN][CONF_APPS].data
                            ),
                        ]
                    ),
                }
            )

        return self.async_show_form(step_id="init", data_schema=options)
Esempio n. 3
0
    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))
Esempio n. 4
0
}

MOCK_TV_CONFIG_NO_TOKEN = {
    CONF_NAME: NAME,
    CONF_HOST: HOST,
    CONF_DEVICE_CLASS: DEVICE_CLASS_TV,
}

MOCK_SPEAKER_CONFIG = {
    CONF_NAME: NAME,
    CONF_HOST: HOST,
    CONF_DEVICE_CLASS: DEVICE_CLASS_SPEAKER,
}

MOCK_INCLUDE_APPS = {
    CONF_INCLUDE_OR_EXCLUDE: CONF_INCLUDE.title(),
    CONF_APPS_TO_INCLUDE_OR_EXCLUDE: [CURRENT_APP],
}
MOCK_INCLUDE_NO_APPS = {
    CONF_INCLUDE_OR_EXCLUDE: CONF_INCLUDE.title(),
    CONF_APPS_TO_INCLUDE_OR_EXCLUDE: [],
}

VIZIO_ZEROCONF_SERVICE_TYPE = "_viziocast._tcp.local."
ZEROCONF_NAME = f"{NAME}.{VIZIO_ZEROCONF_SERVICE_TYPE}"
ZEROCONF_HOST = HOST.split(":")[0]
ZEROCONF_PORT = HOST.split(":")[1]

MOCK_ZEROCONF_SERVICE_INFO = {
    CONF_TYPE: VIZIO_ZEROCONF_SERVICE_TYPE,
    CONF_NAME: ZEROCONF_NAME,