Exemplo n.º 1
0
async def get_current_app(vizio: VizioAsync) -> None:
    app_config = await vizio.get_current_app_config()
    app_name = find_app_name(app_config, [APP_HOME, *APPS])

    if app_name:
        if app_name == NO_APP_RUNNING:
            _LOGGER.info("No currently running app")
        elif app_name == UNKNOWN_APP:
            _LOGGER.info(
                "Can't determine the name of the app, the currently running app's config is %s",
                app_config,
            )
        else:
            _LOGGER.info("Currently running app: %s", app_name)
    else:
        _LOGGER.error("Couldn't get currently running app")
Exemplo n.º 2
0
    async def async_update(self) -> None:
        """Retrieve latest state of the device."""
        if not self._model:
            self._model = await self._device.get_model_name()

        if not self._sw_version:
            self._sw_version = await self._device.get_version()

        is_on = await self._device.get_power_state(log_api_exception=False)

        if is_on is None:
            if self._available:
                _LOGGER.warning(
                    "Lost connection to %s", self._config_entry.data[CONF_HOST]
                )
                self._available = False
            return

        if not self._available:
            _LOGGER.info(
                "Restored connection to %s", self._config_entry.data[CONF_HOST]
            )
            self._available = True

        if not is_on:
            self._state = STATE_OFF
            self._volume_level = None
            self._is_volume_muted = None
            self._current_input = None
            self._current_app = None
            self._current_app_config = None
            self._current_sound_mode = None
            return

        self._state = STATE_ON

        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
            if "mute" in audio_settings:
                self._is_volume_muted = audio_settings["mute"].lower() == "on"
            else:
                self._is_volume_muted = None

            if VIZIO_SOUND_MODE in audio_settings:
                self._supported_commands |= SUPPORT_SELECT_SOUND_MODE
                self._current_sound_mode = audio_settings[VIZIO_SOUND_MODE]
                if not self._available_sound_modes:
                    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_

        if not self._available_inputs:
            inputs = await self._device.get_inputs_list(log_api_exception=False)

            # If no inputs returned, end update
            if not inputs:
                return

            self._available_inputs = [input_.name for input_ in inputs]

        # Return before setting app variables if INPUT_APPS isn't in available inputs
        if self._device_class == DEVICE_CLASS_SPEAKER or not any(
            app for app in INPUT_APPS if app in self._available_inputs
        ):
            return

        # Create list of available known apps from known app list after
        # filtering by CONF_INCLUDE/CONF_EXCLUDE
        self._available_apps = self._apps_list(self._device.get_apps_list())

        self._current_app_config = await self._device.get_current_app_config(
            log_api_exception=False
        )

        self._current_app = find_app_name(
            self._current_app_config, [APP_HOME, *APPS, *self._additional_app_configs]
        )

        if self._current_app == NO_APP_RUNNING:
            self._current_app = None
Exemplo n.º 3
0
        # Return before setting app variables if INPUT_APPS isn't in available inputs
        if self._attr_device_class == DEVICE_CLASS_SPEAKER or not any(
                app for app in INPUT_APPS if app in self._available_inputs):
            return

        # Create list of available known apps from known app list after
        # filtering by CONF_INCLUDE/CONF_EXCLUDE
        self._available_apps = self._apps_list(
            [app["name"] for app in self._all_apps])

        self._current_app_config = await self._device.get_current_app_config(
            log_api_exception=False)

        self._attr_app_name = find_app_name(
            self._current_app_config,
            [APP_HOME, *self._all_apps, *self._additional_app_configs],
        )

        if self._attr_app_name == NO_APP_RUNNING:
            self._attr_app_name = None

    def _get_additional_app_names(self) -> list[dict[str, Any]]:
        """Return list of additional apps that were included in configuration.yaml."""
        return [
            additional_app["name"]
            for additional_app in self._additional_app_configs
        ]

    @staticmethod
    async def _async_send_update_options_signal(
            hass: HomeAssistant, config_entry: ConfigEntry) -> None:
Exemplo n.º 4
0
    async def async_update(self) -> None:
        """Retrieve latest state of the device."""
        is_on = await self._device.get_power_state(log_api_exception=False)

        if is_on is None:
            if self._attr_available:
                _LOGGER.warning("Lost connection to %s",
                                self._config_entry.data[CONF_HOST])
                self._attr_available = False
            return

        if not self._attr_available:
            _LOGGER.info("Restored connection to %s",
                         self._config_entry.data[CONF_HOST])
            self._attr_available = True

        if not self._attr_device_info:
            self._attr_device_info = {
                "identifiers": {(DOMAIN, self._attr_unique_id)},
                "name":
                self._attr_name,
                "manufacturer":
                "VIZIO",
                "model":
                await self._device.get_model_name(log_api_exception=False),
                "sw_version":
                await self._device.get_version(log_api_exception=False),
            }

        if not is_on:
            self._attr_state = STATE_OFF
            self._attr_volume_level = None
            self._attr_is_volume_muted = None
            self._current_input = None
            self._attr_app_name = None
            self._current_app_config = None
            self._attr_sound_mode = None
            return

        self._attr_state = STATE_ON

        audio_settings = await self._device.get_all_settings(
            VIZIO_AUDIO_SETTINGS, log_api_exception=False)

        if audio_settings:
            self._attr_volume_level = (float(audio_settings[VIZIO_VOLUME]) /
                                       self._max_volume)
            if VIZIO_MUTE in audio_settings:
                self._attr_is_volume_muted = (
                    audio_settings[VIZIO_MUTE].lower() == VIZIO_MUTE_ON)
            else:
                self._attr_is_volume_muted = None

            if VIZIO_SOUND_MODE in audio_settings:
                self._attr_supported_features |= SUPPORT_SELECT_SOUND_MODE
                self._attr_sound_mode = audio_settings[VIZIO_SOUND_MODE]
                if not self._attr_sound_mode_list:
                    self._attr_sound_mode_list = await self._device.get_setting_options(
                        VIZIO_AUDIO_SETTINGS,
                        VIZIO_SOUND_MODE,
                        log_api_exception=False,
                    )
            else:
                # Explicitly remove SUPPORT_SELECT_SOUND_MODE from supported features
                self._attr_supported_features &= ~SUPPORT_SELECT_SOUND_MODE

        input_ = await self._device.get_current_input(log_api_exception=False)
        if input_:
            self._current_input = input_

        inputs = await self._device.get_inputs_list(log_api_exception=False)

        # If no inputs returned, end update
        if not inputs:
            return

        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(
                app for app in INPUT_APPS if app in self._available_inputs):
            return

        # Create list of available known apps from known app list after
        # filtering by CONF_INCLUDE/CONF_EXCLUDE
        self._available_apps = self._apps_list(
            [app["name"] for app in self._all_apps])

        self._current_app_config = await self._device.get_current_app_config(
            log_api_exception=False)

        self._attr_app_name = find_app_name(
            self._current_app_config,
            [APP_HOME, *self._all_apps, *self._additional_app_configs],
        )

        if self._attr_app_name == NO_APP_RUNNING:
            self._attr_app_name = None