2019-04-18 20:48:05 +00:00
|
|
|
"""Vizio SmartCast Device support."""
|
2021-03-18 13:43:52 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-01-30 21:13:45 +00:00
|
|
|
from datetime import timedelta
|
2018-01-21 06:35:38 +00:00
|
|
|
import logging
|
2021-05-04 21:36:48 +00:00
|
|
|
from typing import Any
|
2019-10-12 12:09:39 +00:00
|
|
|
|
2020-01-10 02:53:47 +00:00
|
|
|
from pyvizio import VizioAsync
|
2020-03-25 16:35:36 +00:00
|
|
|
from pyvizio.api.apps import find_app_name
|
2020-09-02 09:55:10 +00:00
|
|
|
from pyvizio.const import APP_HOME, INPUT_APPS, NO_APP_RUNNING, UNKNOWN_APP
|
2019-10-12 12:09:39 +00:00
|
|
|
|
2020-03-05 21:34:12 +00:00
|
|
|
from homeassistant.components.media_player import (
|
|
|
|
DEVICE_CLASS_SPEAKER,
|
2020-09-02 09:55:10 +00:00
|
|
|
DEVICE_CLASS_TV,
|
2020-04-03 02:48:19 +00:00
|
|
|
SUPPORT_SELECT_SOUND_MODE,
|
2020-04-25 16:00:57 +00:00
|
|
|
MediaPlayerEntity,
|
2020-03-05 21:34:12 +00:00
|
|
|
)
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2017-07-11 20:55:46 +00:00
|
|
|
from homeassistant.const import (
|
2019-04-18 20:48:05 +00:00
|
|
|
CONF_ACCESS_TOKEN,
|
|
|
|
CONF_DEVICE_CLASS,
|
2020-03-05 21:34:12 +00:00
|
|
|
CONF_EXCLUDE,
|
2019-04-18 20:48:05 +00:00
|
|
|
CONF_HOST,
|
2020-03-05 21:34:12 +00:00
|
|
|
CONF_INCLUDE,
|
2019-04-18 20:48:05 +00:00
|
|
|
CONF_NAME,
|
|
|
|
STATE_OFF,
|
2019-07-31 19:25:30 +00:00
|
|
|
STATE_ON,
|
2019-04-18 20:48:05 +00:00
|
|
|
)
|
2021-04-22 14:53:57 +00:00
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2020-08-07 02:43:03 +00:00
|
|
|
from homeassistant.helpers import entity_platform
|
2020-01-10 02:53:47 +00:00
|
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
from homeassistant.helpers.dispatcher import (
|
|
|
|
async_dispatcher_connect,
|
|
|
|
async_dispatcher_send,
|
|
|
|
)
|
2021-05-04 21:36:48 +00:00
|
|
|
from homeassistant.helpers.entity import DeviceInfo
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2020-09-02 09:55:10 +00:00
|
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2020-01-18 08:15:06 +00:00
|
|
|
from .const import (
|
2020-03-05 21:34:12 +00:00
|
|
|
CONF_ADDITIONAL_CONFIGS,
|
|
|
|
CONF_APPS,
|
2020-01-18 08:15:06 +00:00
|
|
|
CONF_VOLUME_STEP,
|
2020-01-22 09:13:35 +00:00
|
|
|
DEFAULT_TIMEOUT,
|
2020-01-18 08:15:06 +00:00
|
|
|
DEFAULT_VOLUME_STEP,
|
|
|
|
DEVICE_ID,
|
|
|
|
DOMAIN,
|
|
|
|
ICON,
|
2020-08-07 02:43:03 +00:00
|
|
|
SERVICE_UPDATE_SETTING,
|
2020-01-18 08:15:06 +00:00
|
|
|
SUPPORTED_COMMANDS,
|
2020-08-07 02:43:03 +00:00
|
|
|
UPDATE_SETTING_SCHEMA,
|
2020-04-03 02:48:19 +00:00
|
|
|
VIZIO_AUDIO_SETTINGS,
|
2020-01-18 08:15:06 +00:00
|
|
|
VIZIO_DEVICE_CLASSES,
|
2020-08-07 02:43:03 +00:00
|
|
|
VIZIO_MUTE,
|
2020-05-31 08:03:11 +00:00
|
|
|
VIZIO_MUTE_ON,
|
2020-04-03 02:48:19 +00:00
|
|
|
VIZIO_SOUND_MODE,
|
2020-08-07 02:43:03 +00:00
|
|
|
VIZIO_VOLUME,
|
2020-01-18 08:15:06 +00:00
|
|
|
)
|
2018-01-21 06:35:38 +00:00
|
|
|
|
2020-01-07 01:32:31 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2018-01-21 06:35:38 +00:00
|
|
|
|
2020-08-07 02:43:03 +00:00
|
|
|
SCAN_INTERVAL = timedelta(seconds=30)
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
PARALLEL_UPDATES = 0
|
|
|
|
|
2019-04-18 20:48:05 +00:00
|
|
|
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
async def async_setup_entry(
|
2021-04-22 14:53:57 +00:00
|
|
|
hass: HomeAssistant,
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
config_entry: ConfigEntry,
|
2021-05-04 21:36:48 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
2020-01-22 09:13:35 +00:00
|
|
|
) -> None:
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
"""Set up a Vizio media player entry."""
|
|
|
|
host = config_entry.data[CONF_HOST]
|
|
|
|
token = config_entry.data.get(CONF_ACCESS_TOKEN)
|
|
|
|
name = config_entry.data[CONF_NAME]
|
2020-01-18 08:15:06 +00:00
|
|
|
device_class = config_entry.data[CONF_DEVICE_CLASS]
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
|
|
|
|
# If config entry options not set up, set them up, otherwise assign values managed in options
|
2020-01-30 21:13:45 +00:00
|
|
|
volume_step = config_entry.options.get(
|
2020-03-04 09:04:52 +00:00
|
|
|
CONF_VOLUME_STEP, config_entry.data.get(CONF_VOLUME_STEP, DEFAULT_VOLUME_STEP)
|
2020-01-30 21:13:45 +00:00
|
|
|
)
|
2020-02-25 03:35:28 +00:00
|
|
|
|
|
|
|
params = {}
|
2020-01-18 08:15:06 +00:00
|
|
|
if not config_entry.options:
|
2020-02-25 03:35:28 +00:00
|
|
|
params["options"] = {CONF_VOLUME_STEP: volume_step}
|
2020-09-02 09:55:10 +00:00
|
|
|
|
2020-03-13 11:16:24 +00:00
|
|
|
include_or_exclude_key = next(
|
|
|
|
(
|
|
|
|
key
|
|
|
|
for key in config_entry.data.get(CONF_APPS, {})
|
|
|
|
if key in [CONF_INCLUDE, CONF_EXCLUDE]
|
|
|
|
),
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
if include_or_exclude_key:
|
|
|
|
params["options"][CONF_APPS] = {
|
|
|
|
include_or_exclude_key: config_entry.data[CONF_APPS][
|
|
|
|
include_or_exclude_key
|
|
|
|
].copy()
|
|
|
|
}
|
2020-02-25 03:35:28 +00:00
|
|
|
|
|
|
|
if not config_entry.data.get(CONF_VOLUME_STEP):
|
|
|
|
new_data = config_entry.data.copy()
|
|
|
|
new_data.update({CONF_VOLUME_STEP: volume_step})
|
|
|
|
params["data"] = new_data
|
|
|
|
|
|
|
|
if params:
|
|
|
|
hass.config_entries.async_update_entry(config_entry, **params)
|
2020-01-10 02:53:47 +00:00
|
|
|
|
|
|
|
device = VizioAsync(
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
DEVICE_ID,
|
|
|
|
host,
|
|
|
|
name,
|
2020-01-23 00:55:34 +00:00
|
|
|
auth_token=token,
|
|
|
|
device_type=VIZIO_DEVICE_CLASSES[device_class],
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
session=async_get_clientsession(hass, False),
|
2020-01-22 09:13:35 +00:00
|
|
|
timeout=DEFAULT_TIMEOUT,
|
2020-01-10 02:53:47 +00:00
|
|
|
)
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
|
2020-09-02 09:55:10 +00:00
|
|
|
apps_coordinator = hass.data[DOMAIN].get(CONF_APPS)
|
|
|
|
|
|
|
|
entity = VizioDevice(config_entry, device, name, device_class, apps_coordinator)
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2020-01-23 00:55:34 +00:00
|
|
|
async_add_entities([entity], update_before_add=True)
|
2021-05-03 16:34:28 +00:00
|
|
|
platform = entity_platform.async_get_current_platform()
|
2020-08-07 02:43:03 +00:00
|
|
|
platform.async_register_entity_service(
|
|
|
|
SERVICE_UPDATE_SETTING, UPDATE_SETTING_SCHEMA, "async_update_setting"
|
|
|
|
)
|
2017-07-11 20:55:46 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:00:57 +00:00
|
|
|
class VizioDevice(MediaPlayerEntity):
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Media Player implementation which performs REST requests to device."""
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2020-01-10 02:53:47 +00:00
|
|
|
def __init__(
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
self,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
device: VizioAsync,
|
|
|
|
name: str,
|
2020-01-18 08:15:06 +00:00
|
|
|
device_class: str,
|
2020-09-02 09:55:10 +00:00
|
|
|
apps_coordinator: DataUpdateCoordinator,
|
2020-01-10 02:53:47 +00:00
|
|
|
) -> None:
|
2017-07-11 20:55:46 +00:00
|
|
|
"""Initialize Vizio device."""
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
self._config_entry = config_entry
|
2020-09-02 09:55:10 +00:00
|
|
|
self._apps_coordinator = apps_coordinator
|
2019-04-18 20:48:05 +00:00
|
|
|
|
2017-07-11 20:55:46 +00:00
|
|
|
self._name = name
|
2019-01-24 07:20:20 +00:00
|
|
|
self._state = None
|
2017-07-11 20:55:46 +00:00
|
|
|
self._volume_level = None
|
2020-03-13 11:16:24 +00:00
|
|
|
self._volume_step = config_entry.options[CONF_VOLUME_STEP]
|
2020-05-01 04:05:45 +00:00
|
|
|
self._is_volume_muted = None
|
2017-07-11 20:55:46 +00:00
|
|
|
self._current_input = None
|
2020-03-05 21:34:12 +00:00
|
|
|
self._current_app = None
|
2020-03-25 16:35:36 +00:00
|
|
|
self._current_app_config = None
|
2020-04-03 02:48:19 +00:00
|
|
|
self._current_sound_mode = None
|
2020-05-17 10:13:53 +00:00
|
|
|
self._available_sound_modes = []
|
2020-03-05 21:34:12 +00:00
|
|
|
self._available_inputs = []
|
|
|
|
self._available_apps = []
|
2020-09-02 09:55:10 +00:00
|
|
|
self._all_apps = apps_coordinator.data if apps_coordinator else None
|
2020-03-13 11:16:24 +00:00
|
|
|
self._conf_apps = config_entry.options.get(CONF_APPS, {})
|
|
|
|
self._additional_app_configs = config_entry.data.get(CONF_APPS, {}).get(
|
|
|
|
CONF_ADDITIONAL_CONFIGS, []
|
|
|
|
)
|
2020-01-18 08:15:06 +00:00
|
|
|
self._device_class = device_class
|
|
|
|
self._supported_commands = SUPPORTED_COMMANDS[device_class]
|
2020-01-10 02:53:47 +00:00
|
|
|
self._device = device
|
2019-04-18 20:48:05 +00:00
|
|
|
self._max_volume = float(self._device.get_max_volume())
|
2020-01-18 08:15:06 +00:00
|
|
|
self._icon = ICON[device_class]
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
self._available = True
|
2020-02-03 07:41:58 +00:00
|
|
|
self._model = None
|
|
|
|
self._sw_version = None
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2021-03-18 13:43:52 +00:00
|
|
|
def _apps_list(self, apps: list[str]) -> list[str]:
|
2020-03-05 21:34:12 +00:00
|
|
|
"""Return process apps list based on configured filters."""
|
|
|
|
if self._conf_apps.get(CONF_INCLUDE):
|
|
|
|
return [app for app in apps if app in self._conf_apps[CONF_INCLUDE]]
|
|
|
|
|
|
|
|
if self._conf_apps.get(CONF_EXCLUDE):
|
|
|
|
return [app for app in apps if app not in self._conf_apps[CONF_EXCLUDE]]
|
|
|
|
|
|
|
|
return apps
|
|
|
|
|
2020-01-10 02:53:47 +00:00
|
|
|
async def async_update(self) -> None:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Retrieve latest state of the device."""
|
2020-01-23 00:55:34 +00:00
|
|
|
is_on = await self._device.get_power_state(log_api_exception=False)
|
2019-02-28 00:08:02 +00:00
|
|
|
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
if is_on is None:
|
2020-01-30 21:13:45 +00:00
|
|
|
if self._available:
|
|
|
|
_LOGGER.warning(
|
|
|
|
"Lost connection to %s", self._config_entry.data[CONF_HOST]
|
|
|
|
)
|
|
|
|
self._available = False
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
return
|
2020-01-10 02:53:47 +00:00
|
|
|
|
2020-01-30 21:13:45 +00:00
|
|
|
if not self._available:
|
|
|
|
_LOGGER.info(
|
|
|
|
"Restored connection to %s", self._config_entry.data[CONF_HOST]
|
|
|
|
)
|
|
|
|
self._available = True
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
|
2021-02-24 19:15:47 +00:00
|
|
|
if not self._model:
|
|
|
|
self._model = await self._device.get_model_name(log_api_exception=False)
|
|
|
|
|
|
|
|
if not self._sw_version:
|
|
|
|
self._sw_version = await self._device.get_version(log_api_exception=False)
|
|
|
|
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
if not is_on:
|
|
|
|
self._state = STATE_OFF
|
|
|
|
self._volume_level = None
|
2020-05-01 04:05:45 +00:00
|
|
|
self._is_volume_muted = None
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
self._current_input = None
|
2020-03-12 14:04:34 +00:00
|
|
|
self._current_app = None
|
2020-03-25 16:35:36 +00:00
|
|
|
self._current_app_config = None
|
2020-04-03 02:48:19 +00:00
|
|
|
self._current_sound_mode = None
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
return
|
2020-01-07 01:32:31 +00:00
|
|
|
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
self._state = STATE_ON
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2020-04-03 02:48:19 +00:00
|
|
|
audio_settings = await self._device.get_all_settings(
|
|
|
|
VIZIO_AUDIO_SETTINGS, log_api_exception=False
|
2020-03-04 09:04:52 +00:00
|
|
|
)
|
2020-08-07 02:43:03 +00:00
|
|
|
|
2020-05-31 08:03:11 +00:00
|
|
|
if audio_settings:
|
2020-08-07 02:43:03 +00:00
|
|
|
self._volume_level = float(audio_settings[VIZIO_VOLUME]) / self._max_volume
|
|
|
|
if VIZIO_MUTE in audio_settings:
|
|
|
|
self._is_volume_muted = (
|
|
|
|
audio_settings[VIZIO_MUTE].lower() == VIZIO_MUTE_ON
|
|
|
|
)
|
2020-05-01 04:05:45 +00:00
|
|
|
else:
|
|
|
|
self._is_volume_muted = None
|
2019-02-28 00:08:02 +00:00
|
|
|
|
2020-04-03 02:48:19 +00:00
|
|
|
if VIZIO_SOUND_MODE in audio_settings:
|
|
|
|
self._supported_commands |= SUPPORT_SELECT_SOUND_MODE
|
|
|
|
self._current_sound_mode = audio_settings[VIZIO_SOUND_MODE]
|
2020-05-17 10:13:53 +00:00
|
|
|
if not self._available_sound_modes:
|
2020-08-27 11:56:20 +00:00
|
|
|
self._available_sound_modes = (
|
|
|
|
await self._device.get_setting_options(
|
2021-01-01 12:35:05 +00:00
|
|
|
VIZIO_AUDIO_SETTINGS,
|
|
|
|
VIZIO_SOUND_MODE,
|
|
|
|
log_api_exception=False,
|
2020-08-27 11:56:20 +00:00
|
|
|
)
|
2020-04-03 02:48:19 +00:00
|
|
|
)
|
|
|
|
else:
|
2020-05-31 08:03:11 +00:00
|
|
|
# Explicitly remove SUPPORT_SELECT_SOUND_MODE from supported features
|
|
|
|
self._supported_commands &= ~SUPPORT_SELECT_SOUND_MODE
|
2020-04-03 02:48:19 +00:00
|
|
|
|
2020-01-23 00:55:34 +00:00
|
|
|
input_ = await self._device.get_current_input(log_api_exception=False)
|
2020-05-31 08:03:11 +00:00
|
|
|
if input_:
|
2020-02-03 07:41:58 +00:00
|
|
|
self._current_input = input_
|
2019-02-28 00:08:02 +00:00
|
|
|
|
2020-05-31 08:03:11 +00:00
|
|
|
inputs = await self._device.get_inputs_list(log_api_exception=False)
|
2020-03-05 21:34:12 +00:00
|
|
|
|
2020-05-31 08:03:11 +00:00
|
|
|
# If no inputs returned, end update
|
|
|
|
if not inputs:
|
|
|
|
return
|
2020-03-05 21:34:12 +00:00
|
|
|
|
2020-05-31 08:03:11 +00:00
|
|
|
self._available_inputs = [input_.name for input_ in inputs]
|
2020-03-05 21:34:12 +00:00
|
|
|
|
|
|
|
# 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
|
2020-09-02 09:55:10 +00:00
|
|
|
self._available_apps = self._apps_list([app["name"] for app in self._all_apps])
|
2020-03-05 21:34:12 +00:00
|
|
|
|
2020-03-25 16:35:36 +00:00
|
|
|
self._current_app_config = await self._device.get_current_app_config(
|
|
|
|
log_api_exception=False
|
|
|
|
)
|
|
|
|
|
|
|
|
self._current_app = find_app_name(
|
2020-09-02 09:55:10 +00:00
|
|
|
self._current_app_config,
|
|
|
|
[APP_HOME, *self._all_apps, *self._additional_app_configs],
|
2020-03-25 16:35:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if self._current_app == NO_APP_RUNNING:
|
|
|
|
self._current_app = None
|
2020-03-05 21:34:12 +00:00
|
|
|
|
2021-03-18 13:43:52 +00:00
|
|
|
def _get_additional_app_names(self) -> list[dict[str, Any]]:
|
2020-03-05 21:34:12 +00:00
|
|
|
"""Return list of additional apps that were included in configuration.yaml."""
|
|
|
|
return [
|
|
|
|
additional_app["name"] for additional_app in self._additional_app_configs
|
|
|
|
]
|
2019-02-28 00:08:02 +00:00
|
|
|
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
@staticmethod
|
|
|
|
async def _async_send_update_options_signal(
|
2021-04-22 14:53:57 +00:00
|
|
|
hass: HomeAssistant, config_entry: ConfigEntry
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
) -> None:
|
2020-01-30 21:13:45 +00:00
|
|
|
"""Send update event when Vizio config entry is updated."""
|
2020-01-18 08:15:06 +00:00
|
|
|
# Move this method to component level if another entity ever gets added for a single config entry.
|
2020-10-02 22:04:11 +00:00
|
|
|
# See here: https://github.com/home-assistant/core/pull/30653#discussion_r366426121
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
async_dispatcher_send(hass, config_entry.entry_id, config_entry)
|
|
|
|
|
|
|
|
async def _async_update_options(self, config_entry: ConfigEntry) -> None:
|
|
|
|
"""Update options if the update signal comes from this entity."""
|
|
|
|
self._volume_step = config_entry.options[CONF_VOLUME_STEP]
|
2020-09-02 09:55:10 +00:00
|
|
|
# Update so that CONF_ADDITIONAL_CONFIGS gets retained for imports
|
2020-03-13 11:16:24 +00:00
|
|
|
self._conf_apps.update(config_entry.options.get(CONF_APPS, {}))
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
|
2020-08-07 02:43:03 +00:00
|
|
|
async def async_update_setting(
|
2021-03-18 13:43:52 +00:00
|
|
|
self, setting_type: str, setting_name: str, new_value: int | str
|
2020-08-07 02:43:03 +00:00
|
|
|
) -> None:
|
|
|
|
"""Update a setting when update_setting service is called."""
|
|
|
|
await self._device.set_setting(
|
2020-08-27 11:56:20 +00:00
|
|
|
setting_type,
|
|
|
|
setting_name,
|
|
|
|
new_value,
|
2021-01-01 12:35:05 +00:00
|
|
|
log_api_exception=False,
|
2020-08-07 02:43:03 +00:00
|
|
|
)
|
|
|
|
|
2020-08-12 14:50:36 +00:00
|
|
|
async def async_added_to_hass(self) -> None:
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
"""Register callbacks when entity is added."""
|
|
|
|
# Register callback for when config entry is updated.
|
2020-09-18 01:13:40 +00:00
|
|
|
self.async_on_remove(
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
self._config_entry.add_update_listener(
|
|
|
|
self._async_send_update_options_signal
|
|
|
|
)
|
|
|
|
)
|
2019-02-28 00:08:02 +00:00
|
|
|
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
# Register callback for update event
|
2020-09-18 01:13:40 +00:00
|
|
|
self.async_on_remove(
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
async_dispatcher_connect(
|
|
|
|
self.hass, self._config_entry.entry_id, self._async_update_options
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-09-02 09:55:10 +00:00
|
|
|
# Register callback for app list updates if device is a TV
|
|
|
|
@callback
|
|
|
|
def apps_list_update():
|
|
|
|
"""Update list of all apps."""
|
|
|
|
self._all_apps = self._apps_coordinator.data
|
|
|
|
self.async_write_ha_state()
|
|
|
|
|
|
|
|
if self._device_class == DEVICE_CLASS_TV:
|
2020-09-18 01:13:40 +00:00
|
|
|
self.async_on_remove(
|
2020-09-02 09:55:10 +00:00
|
|
|
self._apps_coordinator.async_add_listener(apps_list_update)
|
|
|
|
)
|
|
|
|
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
@property
|
|
|
|
def available(self) -> bool:
|
|
|
|
"""Return the availabiliity of the device."""
|
|
|
|
return self._available
|
2017-07-11 20:55:46 +00:00
|
|
|
|
|
|
|
@property
|
2021-03-18 13:43:52 +00:00
|
|
|
def state(self) -> str | None:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Return the state of the device."""
|
2017-07-11 20:55:46 +00:00
|
|
|
return self._state
|
|
|
|
|
|
|
|
@property
|
2020-01-10 02:53:47 +00:00
|
|
|
def name(self) -> str:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Return the name of the device."""
|
2017-07-11 20:55:46 +00:00
|
|
|
return self._name
|
|
|
|
|
2020-01-07 01:32:31 +00:00
|
|
|
@property
|
2020-01-10 02:53:47 +00:00
|
|
|
def icon(self) -> str:
|
2020-01-07 01:32:31 +00:00
|
|
|
"""Return the icon of the device."""
|
|
|
|
return self._icon
|
|
|
|
|
2017-07-11 20:55:46 +00:00
|
|
|
@property
|
2021-03-18 13:43:52 +00:00
|
|
|
def volume_level(self) -> float | None:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Return the volume level of the device."""
|
2017-07-11 20:55:46 +00:00
|
|
|
return self._volume_level
|
|
|
|
|
2020-03-04 09:04:52 +00:00
|
|
|
@property
|
|
|
|
def is_volume_muted(self):
|
|
|
|
"""Boolean if volume is currently muted."""
|
2020-05-01 04:05:45 +00:00
|
|
|
return self._is_volume_muted
|
2020-03-04 09:04:52 +00:00
|
|
|
|
2017-07-11 20:55:46 +00:00
|
|
|
@property
|
2021-03-18 13:43:52 +00:00
|
|
|
def source(self) -> str | None:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Return current input of the device."""
|
2020-03-12 10:01:05 +00:00
|
|
|
if self._current_app is not None and self._current_input in INPUT_APPS:
|
2020-03-05 21:34:12 +00:00
|
|
|
return self._current_app
|
|
|
|
|
2017-07-11 20:55:46 +00:00
|
|
|
return self._current_input
|
|
|
|
|
|
|
|
@property
|
2021-03-18 13:43:52 +00:00
|
|
|
def source_list(self) -> list[str]:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Return list of available inputs of the device."""
|
2020-03-05 21:34:12 +00:00
|
|
|
# If Smartcast app is in input list, and the app list has been retrieved,
|
|
|
|
# show the combination with , otherwise just return inputs
|
|
|
|
if self._available_apps:
|
|
|
|
return [
|
2021-07-19 08:46:09 +00:00
|
|
|
*(
|
2020-03-05 21:34:12 +00:00
|
|
|
_input
|
|
|
|
for _input in self._available_inputs
|
|
|
|
if _input not in INPUT_APPS
|
2021-07-19 08:46:09 +00:00
|
|
|
),
|
2020-03-05 21:34:12 +00:00
|
|
|
*self._available_apps,
|
2021-07-19 08:46:09 +00:00
|
|
|
*(
|
2020-03-22 16:34:00 +00:00
|
|
|
app
|
|
|
|
for app in self._get_additional_app_names()
|
|
|
|
if app not in self._available_apps
|
2021-07-19 08:46:09 +00:00
|
|
|
),
|
2020-03-05 21:34:12 +00:00
|
|
|
]
|
|
|
|
|
2017-07-11 20:55:46 +00:00
|
|
|
return self._available_inputs
|
|
|
|
|
2020-03-05 21:34:12 +00:00
|
|
|
@property
|
2021-03-18 13:43:52 +00:00
|
|
|
def app_id(self) -> str | None:
|
2020-03-25 16:35:36 +00:00
|
|
|
"""Return the ID of the current app if it is unknown by pyvizio."""
|
|
|
|
if self._current_app_config and self.app_name == UNKNOWN_APP:
|
|
|
|
return {
|
|
|
|
"APP_ID": self._current_app_config.APP_ID,
|
|
|
|
"NAME_SPACE": self._current_app_config.NAME_SPACE,
|
|
|
|
"MESSAGE": self._current_app_config.MESSAGE,
|
|
|
|
}
|
|
|
|
|
|
|
|
return None
|
2020-03-05 21:34:12 +00:00
|
|
|
|
|
|
|
@property
|
2021-03-18 13:43:52 +00:00
|
|
|
def app_name(self) -> str | None:
|
2020-03-05 21:34:12 +00:00
|
|
|
"""Return the friendly name of the current app."""
|
|
|
|
return self._current_app
|
|
|
|
|
2017-07-11 20:55:46 +00:00
|
|
|
@property
|
2020-01-10 02:53:47 +00:00
|
|
|
def supported_features(self) -> int:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Flag device features that are supported."""
|
|
|
|
return self._supported_commands
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2020-01-05 10:20:06 +00:00
|
|
|
@property
|
2020-01-10 02:53:47 +00:00
|
|
|
def unique_id(self) -> str:
|
2020-01-05 10:20:06 +00:00
|
|
|
"""Return the unique id of the device."""
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
return self._config_entry.unique_id
|
2020-01-10 02:53:47 +00:00
|
|
|
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
@property
|
2021-05-01 22:37:19 +00:00
|
|
|
def device_info(self) -> DeviceInfo:
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
"""Return device registry information."""
|
|
|
|
return {
|
|
|
|
"identifiers": {(DOMAIN, self._config_entry.unique_id)},
|
|
|
|
"name": self.name,
|
|
|
|
"manufacturer": "VIZIO",
|
2020-02-03 07:41:58 +00:00
|
|
|
"model": self._model,
|
|
|
|
"sw_version": self._sw_version,
|
Add Config Flow support, Device Registry support, available property to vizio component (#30653)
* add config flow support, device registry support, available property
* raise PlatformNotReady if HA cant connect to device
* remove test logging statement and fix integration title
* store import and last user input values so user can see errors next to value that caused error
* add PARALLEL_UPDATES
* add missing type hints
* add missing type hints to tests
* fix options config flow title
* changes based on review
* better key name for message when cant connect
* fix missed update to key name
* fix comments
* remove logger from test which was used to debug and update test function names and docstrings to be more accurate
* add __init__.py to vizio tests module
* readded options flow and updated main component to handle options updates, set unique ID to serial, fixes based on review
* pop hass.data in media_player unload instead of in __init__ since it is set in media_player
* update requirements_all and requirements_test_all
* make unique_id key name a constant
* remove additional line breaks after docstrings
* unload entries during test_user_flow and test_import_flow tests to hopefully reduce teardown time
* try to speed up tests
* remove unnecessary code, use event bus to track options updates, move patches to pytest fixtures and fix patch scoping
* fix comment
* remove translations from commit
* suppress API error logging when checking for device availability as it can spam logs
* update requirements_all and requirements_test_all
* dont pass hass to entity since it is passed to entity anyway, remove entity unload from tests, other misc changes from review
* fix clearing listeners
* use config_entry unique ID for unique ID and use config_entry entry ID as update signal
* update config flow based on suggested changes
* update volume step on config import if it doesn't match config_entry volume step
* update config_entry data and options with new volume step value
* copy entry.data and entry.options before updating when updating config_entry
* fix test_import_entity_already_configured
2020-01-15 10:43:55 +00:00
|
|
|
}
|
2020-01-05 10:20:06 +00:00
|
|
|
|
2020-01-18 08:15:06 +00:00
|
|
|
@property
|
2020-04-03 02:48:19 +00:00
|
|
|
def device_class(self) -> str:
|
2020-01-18 08:15:06 +00:00
|
|
|
"""Return device class for entity."""
|
|
|
|
return self._device_class
|
|
|
|
|
2020-04-03 02:48:19 +00:00
|
|
|
@property
|
2021-03-18 13:43:52 +00:00
|
|
|
def sound_mode(self) -> str | None:
|
2020-04-03 02:48:19 +00:00
|
|
|
"""Name of the current sound mode."""
|
|
|
|
return self._current_sound_mode
|
|
|
|
|
|
|
|
@property
|
2021-03-18 13:43:52 +00:00
|
|
|
def sound_mode_list(self) -> list[str] | None:
|
2020-04-03 02:48:19 +00:00
|
|
|
"""List of available sound modes."""
|
|
|
|
return self._available_sound_modes
|
|
|
|
|
|
|
|
async def async_select_sound_mode(self, sound_mode):
|
|
|
|
"""Select sound mode."""
|
|
|
|
if sound_mode in self._available_sound_modes:
|
|
|
|
await self._device.set_setting(
|
2021-01-01 12:35:05 +00:00
|
|
|
VIZIO_AUDIO_SETTINGS,
|
|
|
|
VIZIO_SOUND_MODE,
|
|
|
|
sound_mode,
|
|
|
|
log_api_exception=False,
|
2020-04-03 02:48:19 +00:00
|
|
|
)
|
|
|
|
|
2020-01-10 02:53:47 +00:00
|
|
|
async def async_turn_on(self) -> None:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Turn the device on."""
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.pow_on(log_api_exception=False)
|
2020-01-10 02:53:47 +00:00
|
|
|
|
|
|
|
async def async_turn_off(self) -> None:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Turn the device off."""
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.pow_off(log_api_exception=False)
|
2020-01-10 02:53:47 +00:00
|
|
|
|
|
|
|
async def async_mute_volume(self, mute: bool) -> None:
|
2017-07-11 20:55:46 +00:00
|
|
|
"""Mute the volume."""
|
|
|
|
if mute:
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.mute_on(log_api_exception=False)
|
2020-05-01 04:05:45 +00:00
|
|
|
self._is_volume_muted = True
|
2017-07-11 20:55:46 +00:00
|
|
|
else:
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.mute_off(log_api_exception=False)
|
2020-05-01 04:05:45 +00:00
|
|
|
self._is_volume_muted = False
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2020-01-10 02:53:47 +00:00
|
|
|
async def async_media_previous_track(self) -> None:
|
2017-07-11 20:55:46 +00:00
|
|
|
"""Send previous channel command."""
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.ch_down(log_api_exception=False)
|
2020-01-10 02:53:47 +00:00
|
|
|
|
|
|
|
async def async_media_next_track(self) -> None:
|
2017-07-11 20:55:46 +00:00
|
|
|
"""Send next channel command."""
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.ch_up(log_api_exception=False)
|
2020-01-10 02:53:47 +00:00
|
|
|
|
|
|
|
async def async_select_source(self, source: str) -> None:
|
2017-07-11 20:55:46 +00:00
|
|
|
"""Select input source."""
|
2020-03-05 21:34:12 +00:00
|
|
|
if source in self._available_inputs:
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.set_input(source, log_api_exception=False)
|
2020-03-05 21:34:12 +00:00
|
|
|
elif source in self._get_additional_app_names():
|
|
|
|
await self._device.launch_app_config(
|
|
|
|
**next(
|
|
|
|
app["config"]
|
|
|
|
for app in self._additional_app_configs
|
|
|
|
if app["name"] == source
|
2021-01-01 12:35:05 +00:00
|
|
|
),
|
|
|
|
log_api_exception=False,
|
2020-03-05 21:34:12 +00:00
|
|
|
)
|
|
|
|
elif source in self._available_apps:
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.launch_app(
|
|
|
|
source, self._all_apps, log_api_exception=False
|
|
|
|
)
|
2020-01-10 02:53:47 +00:00
|
|
|
|
|
|
|
async def async_volume_up(self) -> None:
|
2020-01-30 21:13:45 +00:00
|
|
|
"""Increase volume of the device."""
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.vol_up(num=self._volume_step, log_api_exception=False)
|
2020-01-10 02:53:47 +00:00
|
|
|
|
2019-07-10 22:58:29 +00:00
|
|
|
if self._volume_level is not None:
|
2019-07-31 19:25:30 +00:00
|
|
|
self._volume_level = min(
|
|
|
|
1.0, self._volume_level + self._volume_step / self._max_volume
|
|
|
|
)
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2020-01-10 02:53:47 +00:00
|
|
|
async def async_volume_down(self) -> None:
|
2020-01-30 21:13:45 +00:00
|
|
|
"""Decrease volume of the device."""
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.vol_down(num=self._volume_step, log_api_exception=False)
|
2020-01-10 02:53:47 +00:00
|
|
|
|
2019-07-10 22:58:29 +00:00
|
|
|
if self._volume_level is not None:
|
2019-07-31 19:25:30 +00:00
|
|
|
self._volume_level = max(
|
|
|
|
0.0, self._volume_level - self._volume_step / self._max_volume
|
|
|
|
)
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2020-01-10 02:53:47 +00:00
|
|
|
async def async_set_volume_level(self, volume: float) -> None:
|
2018-06-18 04:06:53 +00:00
|
|
|
"""Set volume level."""
|
|
|
|
if self._volume_level is not None:
|
|
|
|
if volume > self._volume_level:
|
2019-04-18 20:48:05 +00:00
|
|
|
num = int(self._max_volume * (volume - self._volume_level))
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.vol_up(num=num, log_api_exception=False)
|
2018-06-18 04:06:53 +00:00
|
|
|
self._volume_level = volume
|
2020-01-23 00:55:34 +00:00
|
|
|
|
2018-06-18 04:06:53 +00:00
|
|
|
elif volume < self._volume_level:
|
2019-04-18 20:48:05 +00:00
|
|
|
num = int(self._max_volume * (self._volume_level - volume))
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.vol_down(num=num, log_api_exception=False)
|
2018-06-18 04:06:53 +00:00
|
|
|
self._volume_level = volume
|