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 (
|
2020-04-03 02:48:19 +00:00
|
|
|
SUPPORT_SELECT_SOUND_MODE,
|
2022-02-15 09:51:55 +00:00
|
|
|
MediaPlayerDeviceClass,
|
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-10-28 16:24:40 +00:00
|
|
|
from homeassistant.helpers.entity import DeviceInfo
|
2021-05-04 21:36:48 +00:00
|
|
|
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, {})
|
2021-07-29 23:20:03 +00:00
|
|
|
if key in (CONF_INCLUDE, CONF_EXCLUDE)
|
2020-03-13 11:16:24 +00:00
|
|
|
),
|
|
|
|
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
|
|
|
|
2020-03-13 11:16:24 +00:00
|
|
|
self._volume_step = config_entry.options[CONF_VOLUME_STEP]
|
2017-07-11 20:55:46 +00:00
|
|
|
self._current_input = None
|
2020-03-25 16:35:36 +00:00
|
|
|
self._current_app_config = None
|
2022-02-14 07:49:19 +00:00
|
|
|
self._attr_app_name = None
|
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-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())
|
2021-09-27 18:20:15 +00:00
|
|
|
|
|
|
|
# Entity class attributes that will change with each update (we only include
|
|
|
|
# the ones that are initialized differently from the defaults)
|
|
|
|
self._attr_sound_mode_list = []
|
|
|
|
self._attr_supported_features = SUPPORTED_COMMANDS[device_class]
|
|
|
|
|
|
|
|
# Entity class attributes that will not change
|
|
|
|
self._attr_name = name
|
|
|
|
self._attr_icon = ICON[device_class]
|
|
|
|
self._attr_unique_id = self._config_entry.unique_id
|
|
|
|
self._attr_device_class = device_class
|
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."""
|
2022-01-13 19:59:55 +00:00
|
|
|
if (
|
|
|
|
is_on := await self._device.get_power_state(log_api_exception=False)
|
|
|
|
) is None:
|
2021-09-27 18:20:15 +00:00
|
|
|
if self._attr_available:
|
2020-01-30 21:13:45 +00:00
|
|
|
_LOGGER.warning(
|
|
|
|
"Lost connection to %s", self._config_entry.data[CONF_HOST]
|
|
|
|
)
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_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
|
|
|
|
2021-09-27 18:20:15 +00:00
|
|
|
if not self._attr_available:
|
2020-01-30 21:13:45 +00:00
|
|
|
_LOGGER.info(
|
|
|
|
"Restored connection to %s", self._config_entry.data[CONF_HOST]
|
|
|
|
)
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_available = True
|
|
|
|
|
|
|
|
if not self._attr_device_info:
|
2021-10-28 16:24:40 +00:00
|
|
|
self._attr_device_info = DeviceInfo(
|
|
|
|
identifiers={(DOMAIN, self._attr_unique_id)},
|
|
|
|
manufacturer="VIZIO",
|
|
|
|
model=await self._device.get_model_name(log_api_exception=False),
|
|
|
|
name=self._attr_name,
|
|
|
|
sw_version=await self._device.get_version(log_api_exception=False),
|
|
|
|
)
|
2021-02-24 19:15: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
|
|
|
if not is_on:
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_state = STATE_OFF
|
|
|
|
self._attr_volume_level = None
|
|
|
|
self._attr_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
|
2022-02-14 07:49:19 +00:00
|
|
|
self._attr_app_name = None
|
2020-03-25 16:35:36 +00:00
|
|
|
self._current_app_config = None
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_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
|
|
|
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_state = STATE_ON
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2022-01-13 19:59:55 +00:00
|
|
|
if audio_settings := await self._device.get_all_settings(
|
2020-04-03 02:48:19 +00:00
|
|
|
VIZIO_AUDIO_SETTINGS, log_api_exception=False
|
2022-01-13 19:59:55 +00:00
|
|
|
):
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_volume_level = (
|
|
|
|
float(audio_settings[VIZIO_VOLUME]) / self._max_volume
|
|
|
|
)
|
2020-08-07 02:43:03 +00:00
|
|
|
if VIZIO_MUTE in audio_settings:
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_is_volume_muted = (
|
2020-08-07 02:43:03 +00:00
|
|
|
audio_settings[VIZIO_MUTE].lower() == VIZIO_MUTE_ON
|
|
|
|
)
|
2020-05-01 04:05:45 +00:00
|
|
|
else:
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_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:
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_supported_features |= SUPPORT_SELECT_SOUND_MODE
|
|
|
|
self._attr_sound_mode = audio_settings[VIZIO_SOUND_MODE]
|
|
|
|
if not self._attr_sound_mode_list:
|
|
|
|
self._attr_sound_mode_list = await self._device.get_setting_options(
|
|
|
|
VIZIO_AUDIO_SETTINGS,
|
|
|
|
VIZIO_SOUND_MODE,
|
|
|
|
log_api_exception=False,
|
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
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_supported_features &= ~SUPPORT_SELECT_SOUND_MODE
|
2020-04-03 02:48:19 +00:00
|
|
|
|
2022-01-13 19:59:55 +00:00
|
|
|
if input_ := await self._device.get_current_input(log_api_exception=False):
|
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
|
|
|
# If no inputs returned, end update
|
2022-01-13 19:59:55 +00:00
|
|
|
if not (inputs := await self._device.get_inputs_list(log_api_exception=False)):
|
2020-05-31 08:03:11 +00:00
|
|
|
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
|
2022-02-15 09:51:55 +00:00
|
|
|
if self._attr_device_class == MediaPlayerDeviceClass.SPEAKER or not any(
|
2020-03-05 21:34:12 +00:00
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2022-02-14 07:49:19 +00:00
|
|
|
self._attr_app_name = 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
|
|
|
)
|
|
|
|
|
2022-02-14 07:49:19 +00:00
|
|
|
if self._attr_app_name == NO_APP_RUNNING:
|
|
|
|
self._attr_app_name = 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."""
|
2022-01-13 19:59:55 +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()
|
|
|
|
|
2022-02-15 09:51:55 +00:00
|
|
|
if self._attr_device_class == MediaPlayerDeviceClass.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)
|
|
|
|
)
|
|
|
|
|
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."""
|
2022-02-14 07:49:19 +00:00
|
|
|
if self._attr_app_name is not None and self._current_input in INPUT_APPS:
|
|
|
|
return self._attr_app_name
|
2020-03-05 21:34:12 +00:00
|
|
|
|
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,
|
2021-09-27 18:20:15 +00:00
|
|
|
# show the combination with, otherwise just return inputs
|
2020-03-05 21:34:12 +00:00
|
|
|
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."""
|
2022-01-13 19:59:55 +00:00
|
|
|
if self._current_app_config and self.source == UNKNOWN_APP:
|
2020-03-25 16:35:36 +00:00
|
|
|
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
|
|
|
|
2020-04-03 02:48:19 +00:00
|
|
|
async def async_select_sound_mode(self, sound_mode):
|
|
|
|
"""Select sound mode."""
|
2021-09-27 18:20:15 +00:00
|
|
|
if sound_mode in self._attr_sound_mode_list:
|
2020-04-03 02:48:19 +00:00
|
|
|
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)
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_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)
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_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
|
|
|
|
2021-09-27 18:20:15 +00:00
|
|
|
if self._attr_volume_level is not None:
|
|
|
|
self._attr_volume_level = min(
|
|
|
|
1.0, self._attr_volume_level + self._volume_step / self._max_volume
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
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
|
|
|
|
2021-09-27 18:20:15 +00:00
|
|
|
if self._attr_volume_level is not None:
|
|
|
|
self._attr_volume_level = max(
|
|
|
|
0.0, self._attr_volume_level - self._volume_step / self._max_volume
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
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."""
|
2021-09-27 18:20:15 +00:00
|
|
|
if self._attr_volume_level is not None:
|
|
|
|
if volume > self._attr_volume_level:
|
|
|
|
num = int(self._max_volume * (volume - self._attr_volume_level))
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.vol_up(num=num, log_api_exception=False)
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_volume_level = volume
|
2020-01-23 00:55:34 +00:00
|
|
|
|
2021-09-27 18:20:15 +00:00
|
|
|
elif volume < self._attr_volume_level:
|
|
|
|
num = int(self._max_volume * (self._attr_volume_level - volume))
|
2021-01-01 12:35:05 +00:00
|
|
|
await self._device.vol_down(num=num, log_api_exception=False)
|
2021-09-27 18:20:15 +00:00
|
|
|
self._attr_volume_level = volume
|