2019-04-18 20:48:05 +00:00
|
|
|
"""Vizio SmartCast Device support."""
|
2020-01-30 21:13:45 +00:00
|
|
|
from datetime import timedelta
|
2018-01-21 06:35:38 +00:00
|
|
|
import logging
|
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 typing import Callable, List
|
2019-10-12 12:09:39 +00:00
|
|
|
|
2020-01-10 02:53:47 +00:00
|
|
|
from pyvizio import VizioAsync
|
2019-10-12 12:09:39 +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.components.media_player import MediaPlayerDevice
|
|
|
|
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,
|
|
|
|
CONF_HOST,
|
|
|
|
CONF_NAME,
|
|
|
|
STATE_OFF,
|
2019-07-31 19:25:30 +00:00
|
|
|
STATE_ON,
|
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
|
|
|
from homeassistant.exceptions import PlatformNotReady
|
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,
|
|
|
|
)
|
2020-01-10 02:53:47 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
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.typing import HomeAssistantType
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2020-01-18 08:15:06 +00:00
|
|
|
from .const import (
|
|
|
|
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,
|
|
|
|
SUPPORTED_COMMANDS,
|
|
|
|
VIZIO_DEVICE_CLASSES,
|
|
|
|
)
|
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-01-30 21:13:45 +00:00
|
|
|
SCAN_INTERVAL = timedelta(seconds=10)
|
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(
|
2020-01-10 02:53:47 +00:00
|
|
|
hass: HomeAssistantType,
|
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,
|
2020-01-10 02:53:47 +00:00
|
|
|
async_add_entities: Callable[[List[Entity], bool], None],
|
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(
|
|
|
|
CONF_VOLUME_STEP, config_entry.data.get(CONF_VOLUME_STEP, DEFAULT_VOLUME_STEP),
|
|
|
|
)
|
2020-01-18 08:15:06 +00:00
|
|
|
if not config_entry.options:
|
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
|
|
|
hass.config_entries.async_update_entry(
|
|
|
|
config_entry, options={CONF_VOLUME_STEP: volume_step}
|
|
|
|
)
|
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-01-10 02:53:47 +00:00
|
|
|
if not await device.can_connect():
|
2020-01-30 21:13:45 +00:00
|
|
|
_LOGGER.warning("Failed to connect to %s", host)
|
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
|
|
|
raise PlatformNotReady
|
|
|
|
|
2020-01-24 06:39:28 +00:00
|
|
|
entity = VizioDevice(config_entry, device, name, volume_step, device_class)
|
2017-07-11 20:55:46 +00:00
|
|
|
|
2020-01-23 00:55:34 +00:00
|
|
|
async_add_entities([entity], update_before_add=True)
|
2017-07-11 20:55:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VizioDevice(MediaPlayerDevice):
|
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,
|
|
|
|
volume_step: int,
|
2020-01-18 08:15:06 +00:00
|
|
|
device_class: str,
|
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
|
|
|
|
self._async_unsub_listeners = []
|
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
|
|
|
|
self._volume_step = volume_step
|
|
|
|
self._current_input = None
|
|
|
|
self._available_inputs = None
|
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
|
2017-07-11 20:55:46 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
if not is_on:
|
|
|
|
self._state = STATE_OFF
|
|
|
|
self._volume_level = None
|
|
|
|
self._current_input = None
|
|
|
|
self._available_inputs = None
|
|
|
|
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-01-23 00:55:34 +00:00
|
|
|
volume = await self._device.get_current_volume(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 volume is not None:
|
|
|
|
self._volume_level = float(volume) / self._max_volume
|
2019-02-28 00:08:02 +00:00
|
|
|
|
2020-01-23 00:55:34 +00:00
|
|
|
input_ = await self._device.get_current_input(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 input_ is not None:
|
|
|
|
self._current_input = input_.meta_name
|
2019-02-28 00:08:02 +00:00
|
|
|
|
2020-01-23 00:55:34 +00:00
|
|
|
inputs = await self._device.get_inputs(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 inputs is not None:
|
|
|
|
self._available_inputs = [input_.name for input_ in inputs]
|
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(
|
|
|
|
hass: HomeAssistantType, config_entry: ConfigEntry
|
|
|
|
) -> 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.
|
|
|
|
# See here: https://github.com/home-assistant/home-assistant/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]
|
|
|
|
|
|
|
|
async def async_added_to_hass(self):
|
|
|
|
"""Register callbacks when entity is added."""
|
|
|
|
# Register callback for when config entry is updated.
|
|
|
|
self._async_unsub_listeners.append(
|
|
|
|
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
|
|
|
|
self._async_unsub_listeners.append(
|
|
|
|
async_dispatcher_connect(
|
|
|
|
self.hass, self._config_entry.entry_id, self._async_update_options
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
async def async_will_remove_from_hass(self):
|
|
|
|
"""Disconnect callbacks when entity is removed."""
|
|
|
|
for listener in self._async_unsub_listeners:
|
|
|
|
listener()
|
|
|
|
|
|
|
|
self._async_unsub_listeners.clear()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self) -> bool:
|
|
|
|
"""Return the availabiliity of the device."""
|
|
|
|
return self._available
|
2017-07-11 20:55:46 +00:00
|
|
|
|
|
|
|
@property
|
2020-01-10 02:53:47 +00:00
|
|
|
def state(self) -> str:
|
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
|
2020-01-10 02:53:47 +00:00
|
|
|
def volume_level(self) -> float:
|
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
|
|
|
|
|
|
|
|
@property
|
2020-01-10 02:53:47 +00:00
|
|
|
def source(self) -> str:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Return current input of the device."""
|
2017-07-11 20:55:46 +00:00
|
|
|
return self._current_input
|
|
|
|
|
|
|
|
@property
|
2020-01-10 02:53:47 +00:00
|
|
|
def source_list(self) -> List:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Return list of available inputs of the device."""
|
2017-07-11 20:55:46 +00:00
|
|
|
return self._available_inputs
|
|
|
|
|
|
|
|
@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
|
|
|
|
def device_info(self):
|
|
|
|
"""Return device registry information."""
|
|
|
|
return {
|
|
|
|
"identifiers": {(DOMAIN, self._config_entry.unique_id)},
|
|
|
|
"name": self.name,
|
|
|
|
"manufacturer": "VIZIO",
|
|
|
|
}
|
2020-01-05 10:20:06 +00:00
|
|
|
|
2020-01-18 08:15:06 +00:00
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return device class for entity."""
|
|
|
|
return self._device_class
|
|
|
|
|
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."""
|
2020-01-10 02:53:47 +00:00
|
|
|
await self._device.pow_on()
|
|
|
|
|
|
|
|
async def async_turn_off(self) -> None:
|
2019-04-18 20:48:05 +00:00
|
|
|
"""Turn the device off."""
|
2020-01-10 02:53:47 +00:00
|
|
|
await self._device.pow_off()
|
|
|
|
|
|
|
|
async def async_mute_volume(self, mute: bool) -> None:
|
2017-07-11 20:55:46 +00:00
|
|
|
"""Mute the volume."""
|
|
|
|
if mute:
|
2020-01-10 02:53:47 +00:00
|
|
|
await self._device.mute_on()
|
2017-07-11 20:55:46 +00:00
|
|
|
else:
|
2020-01-10 02:53:47 +00:00
|
|
|
await self._device.mute_off()
|
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."""
|
2020-01-10 02:53:47 +00:00
|
|
|
await self._device.ch_down()
|
|
|
|
|
|
|
|
async def async_media_next_track(self) -> None:
|
2017-07-11 20:55:46 +00:00
|
|
|
"""Send next channel command."""
|
2020-01-10 02:53:47 +00:00
|
|
|
await self._device.ch_up()
|
|
|
|
|
|
|
|
async def async_select_source(self, source: str) -> None:
|
2017-07-11 20:55:46 +00:00
|
|
|
"""Select input source."""
|
2020-01-10 02:53:47 +00:00
|
|
|
await self._device.input_switch(source)
|
|
|
|
|
|
|
|
async def async_volume_up(self) -> None:
|
2020-01-30 21:13:45 +00:00
|
|
|
"""Increase volume of the device."""
|
2020-01-23 00:55:34 +00:00
|
|
|
await self._device.vol_up(num=self._volume_step)
|
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."""
|
2020-01-23 00:55:34 +00:00
|
|
|
await self._device.vol_down(num=self._volume_step)
|
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))
|
2020-01-23 00:55:34 +00:00
|
|
|
await self._device.vol_up(num=num)
|
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))
|
2020-01-23 00:55:34 +00:00
|
|
|
await self._device.vol_down(num=num)
|
2018-06-18 04:06:53 +00:00
|
|
|
self._volume_level = volume
|