* use media player defined device classes instead of custom ones, add options flow test, add timeout options parameter * make options update error more generic * fix config flow options update logic * simplify logic for options update during import * use platform list for load and unload * update private config flow function name and description * fix grammar in strings.json * update mock config variable names to be more accurate * remove timeout conf option, create device_class property * update requirements * update .coveragerc to indicate that config_flow has tests * fix source of device_class property and move constants to const.py * fix grammar in error message * remove redundant device check in async_setup_entry since device connection is checked during config flow * revert change to async_setup_entry, raise ConfigEntryNotReady if device can't be connected to * update error text * add more context to error text
77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
"""Constants used by vizio component."""
|
|
from datetime import timedelta
|
|
|
|
from pyvizio.const import (
|
|
DEVICE_CLASS_SPEAKER as VIZIO_DEVICE_CLASS_SPEAKER,
|
|
DEVICE_CLASS_TV as VIZIO_DEVICE_CLASS_TV,
|
|
)
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.components.media_player import DEVICE_CLASS_SPEAKER, DEVICE_CLASS_TV
|
|
from homeassistant.components.media_player.const import (
|
|
SUPPORT_NEXT_TRACK,
|
|
SUPPORT_PREVIOUS_TRACK,
|
|
SUPPORT_SELECT_SOURCE,
|
|
SUPPORT_TURN_OFF,
|
|
SUPPORT_TURN_ON,
|
|
SUPPORT_VOLUME_MUTE,
|
|
SUPPORT_VOLUME_SET,
|
|
SUPPORT_VOLUME_STEP,
|
|
)
|
|
from homeassistant.const import (
|
|
CONF_ACCESS_TOKEN,
|
|
CONF_DEVICE_CLASS,
|
|
CONF_HOST,
|
|
CONF_NAME,
|
|
)
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
CONF_VOLUME_STEP = "volume_step"
|
|
|
|
DEFAULT_DEVICE_CLASS = DEVICE_CLASS_TV
|
|
DEFAULT_NAME = "Vizio SmartCast"
|
|
DEFAULT_VOLUME_STEP = 1
|
|
|
|
DEVICE_ID = "pyvizio"
|
|
|
|
DOMAIN = "vizio"
|
|
ICON = {DEVICE_CLASS_TV: "mdi:television", DEVICE_CLASS_SPEAKER: "mdi:speaker"}
|
|
|
|
COMMON_SUPPORTED_COMMANDS = (
|
|
SUPPORT_SELECT_SOURCE
|
|
| SUPPORT_TURN_ON
|
|
| SUPPORT_TURN_OFF
|
|
| SUPPORT_VOLUME_MUTE
|
|
| SUPPORT_VOLUME_SET
|
|
| SUPPORT_VOLUME_STEP
|
|
)
|
|
|
|
SUPPORTED_COMMANDS = {
|
|
DEVICE_CLASS_SPEAKER: COMMON_SUPPORTED_COMMANDS,
|
|
DEVICE_CLASS_TV: (
|
|
COMMON_SUPPORTED_COMMANDS | SUPPORT_NEXT_TRACK | SUPPORT_PREVIOUS_TRACK
|
|
),
|
|
}
|
|
|
|
# Since Vizio component relies on device class, this dict will ensure that changes to
|
|
# the values of DEVICE_CLASS_SPEAKER or DEVICE_CLASS_TV don't require changes to pyvizio.
|
|
VIZIO_DEVICE_CLASSES = {
|
|
DEVICE_CLASS_SPEAKER: VIZIO_DEVICE_CLASS_SPEAKER,
|
|
DEVICE_CLASS_TV: VIZIO_DEVICE_CLASS_TV,
|
|
}
|
|
|
|
VIZIO_SCHEMA = {
|
|
vol.Required(CONF_HOST): cv.string,
|
|
vol.Optional(CONF_ACCESS_TOKEN): cv.string,
|
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
vol.Optional(CONF_DEVICE_CLASS, default=DEFAULT_DEVICE_CLASS): vol.All(
|
|
cv.string, vol.Lower, vol.In([DEVICE_CLASS_TV, DEVICE_CLASS_SPEAKER])
|
|
),
|
|
vol.Optional(CONF_VOLUME_STEP, default=DEFAULT_VOLUME_STEP): vol.All(
|
|
vol.Coerce(int), vol.Range(min=1, max=10)
|
|
),
|
|
}
|
|
|
|
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)
|
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|