Move YAML config to component
This commit is contained in:
committed by
rospogrigio
parent
450060488b
commit
0048ce6d5e
@@ -15,6 +15,7 @@ from homeassistant.const import (
|
||||
CONF_PLATFORM,
|
||||
CONF_SWITCHES,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from . import pytuya
|
||||
from .const import ( # pylint: disable=unused-import
|
||||
@@ -56,6 +57,16 @@ OPTIONS_SCHEMA = vol.Schema(
|
||||
}
|
||||
)
|
||||
|
||||
DEVICE_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CONF_DEVICE_ID): cv.string,
|
||||
vol.Required(CONF_LOCAL_KEY): cv.string,
|
||||
vol.Required(CONF_FRIENDLY_NAME): cv.string,
|
||||
vol.Required(CONF_PROTOCOL_VERSION, default="3.3"): vol.Coerce(float),
|
||||
}
|
||||
)
|
||||
|
||||
PICK_ENTITY_SCHEMA = vol.Schema(
|
||||
{vol.Required(PLATFORM_TO_ADD, default=PLATFORMS[0]): vol.In(PLATFORMS)}
|
||||
)
|
||||
@@ -100,9 +111,12 @@ def gen_dps_strings():
|
||||
return [f"{dp} (value: ?)" for dp in range(1, 256)]
|
||||
|
||||
|
||||
def platform_schema(platform, dps_strings, allow_id=True):
|
||||
def platform_schema(platform, dps_strings, allow_id=True, yaml=False):
|
||||
"""Generate input validation schema for a platform."""
|
||||
schema = {}
|
||||
if yaml:
|
||||
# In YAML mode we force the specified platform to match flow schema
|
||||
schema[vol.Required(CONF_PLATFORM)] = vol.In([platform])
|
||||
if allow_id:
|
||||
schema[vol.Required(CONF_ID)] = vol.In(dps_strings)
|
||||
schema[vol.Required(CONF_FRIENDLY_NAME)] = str
|
||||
@@ -126,6 +140,26 @@ def strip_dps_values(user_input, dps_strings):
|
||||
return stripped
|
||||
|
||||
|
||||
def config_schema():
|
||||
"""Build schema used for setting up component."""
|
||||
entity_schemas = [
|
||||
platform_schema(platform, range(1, 256), yaml=True) for platform in PLATFORMS
|
||||
]
|
||||
return vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.All(
|
||||
cv.ensure_list,
|
||||
[
|
||||
DEVICE_SCHEMA.extend(
|
||||
{vol.Required(CONF_ENTITIES): [vol.Any(*entity_schemas)]}
|
||||
)
|
||||
],
|
||||
)
|
||||
},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
async def validate_input(hass: core.HomeAssistant, data):
|
||||
"""Validate the user input allows us to connect."""
|
||||
tuyainterface = pytuya.TuyaInterface(
|
||||
|
Reference in New Issue
Block a user